How can I move an object at the correct angle from one point to another with script?

In my project i want to move an object(dynamic car) from a point to another via scripting like in this unity tutorial.
But in my project it doesn’t work correctly i have problem with vector math what i made for object rotation.
The object move with a angle to next point but not all the time.When a point have more angle then it doesn’t work. Sometime flow 3 point a then not more.I used for rotation setLocalEurlerAngel() and then try setLocalRotation() it is better but then something happen with object scaling.
here is my project.

you could evaluate the curve at two points (times):

  • time
  • time + 0.1 (some small delta)

this gives you two points
you can then position entity at one point, and make it lookAt the other point, something like this:

1 Like

Yes lookAt() work perfect for entities they haven’t an rigidbody dynamic component,.But i want make car with rigidbody dynamic and i can’ t use lookAt() for rigidbody dynamic entities.

In that case perhaps see what the function does here (mostly last 3 lines) and try to do something similar

1 Like

ok thanks, but i couldn’t understand this.

Does the need to react to hitting objects etc (eg being knocked back when it is hit)? If not, you could use kinematic type rigid body

There’s this project of mine that does something similar to get the cube right side up using torque

Yes, it has to be dynamic, because if the vehicle that the player uses hits it, it should act accordingly.
For the car I will use vehicle.js in this project and here the car is dynamic. I made the necessary changes here. But as I said, the car does not stop on the road because the angle is not calculated correctly while moving between the points. I tried it with LookAt () Kinematics. I just did the example in the link I sent to better understand it, and it works there.
I did the same with the playcanvas but it didn’t give the right result.
Maybe the vector account I made is wrong. In the example of Unity, realtiv vector is calculated with InverseTransformPoint () function. For this reason, I used sub () in playcanvas.

That’s a function on a matrix. PlayCanvas mat4 and mat3 has an inverse function and transformPoint too that you can use in place.

I think Vec3, sub() func. is like unity InverseTransformPoint() func.

I don’t think it is

It’s a function on the transform class which is a 4x4 matrix, not a vector.

Ok maybe i’m wrong but wen i try
with Playcanvas Vector sub()
var a=new pc.Vec3(3,2)
var b=new pc.Vec3(4,4)
var c=b.sub(a)

with unity InverseTransformPoint.

is it just coincidence!?

That should not be the result of b - a given the values posted above. C should be (2,0,1)

Even the values were the same, yes it is coincidence.

I have made a mistake. I changed the vector dimension. I actually wanted to do 2D vector.

Even so, it be (2,1) not (1,2)