Day 101: Character Animation Part 4

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!

--

--

--

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

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

Recommended from Medium

The Ideas Behind React Easy State

Create a Full Stack Banking Application using React

Implementing section logout in a react-native application

Configuring automatic backups for Contentful

Getting Started with React Hooks

How to run mobile testing using Appium in IntellIj

Destructuring in JavaScript

Comprehensive Flow with React & Redux

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
Tyler Smallwood

Tyler Smallwood

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

More from Medium

Creating a HUD

Adding a Main Menu to our UI

2D Mobile: Setting Up The Player

Switch Statements To The Rescue!