Day 101: Character Animation Part 4

Tyler Smallwood
2 min readDec 3, 2021

Objective: Flip the character model to face the direction of movement.

We will start with flipping the character around to face the right direction when moving.

Where we are taking in the players input we will need to check to see if the player is moving. We do this by checking to see if “horizontal” is not equal to zero.

Next we will create a local Vector3 variable called facing and assign it the transform.localEulerAngles.

transform.localEulerAngles is the rotation numbers seen on the game object in the inspector.

We will check to see what way the character is facing by using a lambda expression. This expression is like a if statement just done in one line. We will be assigning facing.y to either 0 or 180 if _direction.z is greater or less than 0.

This lambda written out as an if statement looks like this. The lambda above and the if statement below do the same thing but in less lines. You can refer to Microsoft documentation. https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/operators/lambda-expressions

Now we need to assign the transform.localEulerAngles to equal the facing value.

Now our character flips and faces the direction we are moving in!!
Thank you for reading and have a wonderful day!

--

--

Tyler Smallwood

I am passonate on learning to program and use Unity to become a skillful Unity Developer