transform.LookAt question/movement

With the transform.LookAt you can assign a target or whatever to look at and your object will be facing that way, my question is. Can you make your object look at the direction it is moving? Now another is can you still be pressing the same buttons while it does this, because if your holding “w + d” it will move sideways but wil also turn that way, making you go a different way.

So in essence is there a way to have an object look the way it is traveling, w/o affecting the “W,A,S,D” keys and the way they make it move.

Yes it is possible to make a object look at where its moving. There’s a simple way how to do it and a slightly more complicated one as well.

You need to find the direction you are moving in. That should be fairly easy. Then use either of these two ways…

Method 1:

transform.forward = yourDirection;

Method 2:

transform.rotation = Quaternion.LookRotation(dir);

In method two, what does the dir stand for?

dir stands for the direction vector, in other words it’s the direction your object is looking at.

According to the example given in the documentation, you can obtain a direction vector this way:

Vector3 dir = targetedPosition - currentPosition; where currentPosition and targetedPosition are Vector3.

Yes, Numid is correct on everything there. Sorry If I was not clear. :confused: Its the same yourDirection.