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

Easy Algorithm Tips & Tricks

Detecting Outdated Browsers in Vanilla JavaScript

Stack — Data Structure

RTMP Live Stream Broadcasting From React Native, Kotlin, Flutter, Ionic or Xamarin

Thanks to the community 🙏🏻

Building a VueJS App with Firebase Hosting and Validation

Continuous Development with Nodejs PM2 and Nginx

React vs Vue: In My Opinion.

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

Unity Animation System Part 2

Adding a User Interface to our prototype

Lives and Respawn System in Unity

Day 105: Working with Animation Events in Unity