Useful transform property

I was messing around with an idea for a mobile game with Unity, and need to move a character in the direction it was facing.  I’ve done this before by generating a unit vector from the Y angle (it’s a top down view) using sine/cosine.  However, during a hunt for something unrelated, I found:

        playerTransform.localPosition += playerTransform.forward * velocity * Time.deltaTime;

Where, velocity is the speed the player is moving.  Turns out the transform.forward property returns the vector based on the direction of the transform, no more messy code 😀

 

Leave a Reply