How to rotate a player in 2.5D platformer in Unity
Having no rotation of the player is not a problem if the model is just a capsule. But as soon as you add a more advanced model, it will just look like it is running backwards and forwards instead of always forward. Let’s go over how to fix that.
We will continue to build on the player controller from this article. I have previously shown in this article how to add walk and running animations.
Open up the Player script. Inside the PlayerMovement script check if the player is on the ground and if there is any horizonal input. If input is less than 0 set the rotation to -180, or if input is more than 0 set rotation to 0:
At the end of the PlayerMovement function pass in the speed value to the Animator using Math.Abs. This helper function ensures that the speed value is always positive. If not using this method then the character would not animate when walking/running to the left:
Good luck!