Rotate game object so the Z direction is facing the direction of travel?

Hi

I have a game object travelling along a path. And i am trying to get the angle of the direction of travel so i can rotate the gameobject to face the trajectory.

So far i have a method which gets the slope of the path between 2 very close points and i was applying this to the local rotation like so:

transform.localRotation = Quaternion.Euler(Vector3.Angle(transform.position, PathPosition(timeElapsed + 0.001f),0,0);

PathPosition returns a Vector3 position on the path at a given point in time.

But the rotation is not working, i don’t think i am using the correct argument for Vector3.Angle but not 100% sure on that.

I am not using any of the physics engine. Just basic transform stuff. Does any one know the correct solution to this?

What does “it is not working” mean?