Vector 3? Using it right?

Vector3 lookDir = new Vector3();

lookDir = target.position - myTransform.position;
		
myTransform.rigidbody.velocity = Vector3(lookDir.normalize() * currentSpeed * Time.deltaTime);

With the above vode i am getting the following error

Assets/Scripts/guardChaseAnim.cs(53,58): error CS0119: Expression denotes a type', where a variable’, value' or method group’ was expected

Line 53 is the 3rd line.

You have 2 errors.

It looks like you are trying to call the constructor to create a new Vector3. The issues is that there are no constructors that take a Vector3 as an argument (you can copy it, but that’s not the same).

  //you're basically doing
  velocity = new Vector3( someVec3 );

Which is simply not allowed, fortunately it’s a very easy fix.

myTransform.rigidbody.velocity = Vector3(lookDir.normalize() * currentSpeed * Time.deltaTime);

myTransform.rigidbody.velocity = lookDir.normalized * currentSpeed * Time.deltaTime;
//deleted the constructor call.
//also changed normalize() to normalized. You can also use Vector3.Normalize(lookDir).

No, there are a number of problems.

  1. The variable should be declared on one line. Although using two lines like that might work (does an empty Vector3 constructor work?), but there’s no good reason to do it like that.

    Vector3 lookDir = target.position - myTransform.position;

  2. In C#, you must always use the “new” keyword when creating a new Vector3.

    myTransform.rigidbody.velocity = new Vector3(…

  3. A Vector3 contains 3 floats. You can’t create a Vector3 that contains a Vector3. So in this case you would not actually use “new Vector3” since you already have a Vector3.

  4. All functions are capitalized; there’s nothing called “normalize()”. It would be “Normalize()”. There’s a variable called “normalized”, which maybe is what you mean instead.