Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

error CS1519 (invalid token ";") and CS1001 (identifier expected). Vector 3 problem (Brakeys Multiplayer tutorial ep 2)

The script in the video originally had a plethora of errors, and I’ve tried my best to fix the code and reduce the errors to as few as possible

The errors in my current script are:
Assets\PlayerMotor.cs(9,14): error CS1519: Invalid token ‘=’ in class, struct, or interface member declaration

Assets\PlayerMotor.cs(9,32): error CS1001: Identifier expected

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

My script is:

using UnityEngine;

[RequireComponent(typeof(Rigidbody))]

public class PlayerMotor : MonoBehaviour
{
    
    private Vector3 velocity;
    velocity = new Vector3(zero);

    private Rigidbody rb;

    void Start() 
    {

        rb = GetComponent<Rigidbody>();

    }

    //Gets a movement vector
    public void Move (Vector3 _velocity) 
    {

        velocity = _velocity;
        

    }

    //Run every physics iteration
    void FixedUpdate ()
    {

        PerformMovement();

    }

    //Perfrom movement based on velocity variable
    void PerformMovement() 
    {

        if (velocity != Vector3.zero){
            rb.MovePosition(rb.position + velocity * Time.fixedDeltaTime);
        }

    }
}

>Solution :

  1. You can’t just write code inside class body like: velocity = new Vector3(zero);. What you can do, and what probably made you thought you could do that, is to initialize the variable at declaration: private Vector3 velocity = new Vector3(zero); Still, this has more issues.

  2. Vector3 doesn’t have a constructor, that accepts only one parameter.

  3. Even if it did, you would have to declare Vector3 zero as a static variable.

  4. All in all, just use Vector3.zero where you need, there’s no point in declaring it yourself.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading