
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.
