Rotate object to face movement direction

Hello everybody,

I have a problem in Unity which I don’t know how to solve it. I have seen several similar threads already, but I didn’t find a solution to the problem. Maybe that’s because I don’t understand completely how Unity is working.

So I am trying to move an object from position A to position B. The y-coordinate doesn’t affect the movement of the object. I have already established a system in which the object moves a certain pattern (a drone searching for the shortest distance to lead a car to a free parking place). Now I have done that and it works fine, but it looks terrible cause the object doesn’t turn to the direction it’s moving.

So I have tried some methods, like:

drone.transform.localRotation = Quaternion.RotateTowards(drone.transform.localRotation, Quaternion.LookRotation(new Vector3 (entryX, 0.0f, entryZ)), 1000f * Time.deltaTime);

The drone rotates, but not in the direction it’s heading. Moreover the rotation affects how the drone is moving further, kinda ruining the aspect how it leads the car to a free parking place.

Is there a way how I can rotate the drone without affecting the movement?

Thanks in advance.

Assuming your model faces such that it moves along the forward axis, you can treat the movement as a direction vector.

eg
transform.rotation = Quaternion.LookRotation(rigidBody.velocity);

Note that the rotation done this way is a world rotation, not a local rotation