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!




Unity / C# Game developer

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Automated visual testing — how to improve UI verification

Android Parallels For Mac

LeetCode Bi-Weekly Contest 71 (Q2)

Streaming Google Analytics data into Kafka with Snowplow in real-time

Drupal Needs to Improve to Reach the Top of the Game

“LINER for iOS” is Live on Product Hunt!!!

GitHub Enterprise backup using Kubernetes Jobs and upload to AWS S3

My First Project

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Niklas Bergstrand

Niklas Bergstrand

Unity / C# Game developer

More from Medium

How to Vote for Vitoge_SBP and get Vite, Vitoge and Vicat daily payout !

New and Delete in Cpp 11/14/17

In an Era of Fake News, Can the Two-Step Flow Communication Theory Help Us Become Better Media…

10 hours of Travelling ||First Traffic Jam Ever||