I want my player to "face" the direction they're moving, or if not moving, face the last movement direction. There are two solutions I see most often, using rotation (usually Transform.LookAt) or a "forward" vector, transform.forward.

Is there a reason to use one or the other? What do I gain/lose by using one over the other?

For the time being I'm updating transform.forward with a normalized vector of my character movement, unless it's 0,0. That doesn't work 100% so I have some logic left, but I want to understand why this isn't done using rotation.


Use Transform.LookAt()

I didn't even realize that Transform.forward was even assignable until I peeked at the documentation just now, but even so I wouldn't do that; it feels improper.

Transform.LookAt() will be more reliable, as it should be able to handle a 0,0 vector more easily, just make sure to add the movement vector to the player position vector before passing it into LookAt() or your player will always look towards scene origin!

  • \$\begingroup\$ I didn't know that was possible either. It just feels dirty. \$\endgroup\$ – Stephan Jan 2 '18 at 17:42

Perhaps you should use Quaternion.LookRotation, simply passing in your velocity vector as the “forward” argument, and then just assign that to transform.rotation. Slightly less maths involved overall, and at least for me it would be conceptually easier to parse. You don’t have to worry about offsetting to a point in space or anything.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.