How to flip a 3D model

How to face the correction position instead of moonwalking

Now that we have completed all of the necessary animations (idle, running, jumping) it is time to fix the issues of facing the correct position while moving left and right.

Scripting for character rotation:

Firstly to understand the logic behind flipping the player character when it is moving a certain direction. Since our player’s movement is calculating a float value for speed, we must make sure that we don’t confused movement and idling.

In the same IF statement within the Update method, we will create a new if statement targeting when the horizontalInput does NOT equal Zero. This is how we limit the confusion between Running and Idle.

Then we need to create a Vector3 variable that addresses our transform local Euler Angles. Local Euler Angles are the X and Y and Z values of the local game object (which in this case is the the Player). Using the new variable, we will only need to change the Y rotation according to the direction of the Z axis. If the direction is greater than 0 then our direction is 0. Else we will be set to 180.

After assigning the Y rotation we will reapply the local Euler Angles back to the current transform unit.

Now your character should rotate upon facing the correct direction, and when you stop moving the character will stay idle within the same direction we current are.

A Designer, an Illustrator and a massive tech geek aspiring to become a professional Unity Developer.

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

Recommended from Medium

Introducing Cell Atoms & Molecules

My First Foray into Serverless with AWS

Best Practices for using Text Input component in React Native

Rethink Modals Management in React

How to Add a Config File to a Java Project

Create a CSS Theme Switcher Using Gatsby and TailwindCSS

Internationalization of Spring Boot RESTful Services

https://concept-tees.myspreadshop.com/embrace+the+grind+red+white+print-A5d1175b220517672b46cd271

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
Simon Truong

Simon Truong

A Designer, an Illustrator and a massive tech geek aspiring to become a professional Unity Developer.

More from Medium

Until Saturday

Hey Ma, I wanna be a writer some day!

Mother-Daughter

Covid-19 Disinformation Online