Blend Trees for Movement

Bools and triggers don’t take float values, they are on or off, true or false. For movement, that’s a 2D float on the x and y. For that, we need to use floats and something called a blend tree. Right click and create your blend tree.

Call this your idle tree.

You have several options for your blend tree. For this position, we will do a 2D Simple. We now need to create 2 float values that we will feed into the parameter value for move x and move z.

Now whatever value we feed into the move parameters will control our motions. Let’s add our idle and our walk animations to our tree. Create 5 motion values. Now place them from idle and all around.

Pretend this is a top down view. Place the points apporopriately with the idle in the center, the forward walk at 0, 1, ect.

We want to create a walk tree function that pipes in the input.x and input.y values from our custom controls into the first person controller. Also add the function WalkTree to run in the move section of the FPC.

Once we do this, we need to make sure our idle tree takes over for our original idle and our float values are piped into our blend tree.

Playing it back, it works, but we get sharp cuts between movements. Let’s add some blending.

To do this, we should do a mathf.lerp. Create two floats — velocityx and y.

In our code, we will make velocity x lerp between velocity x and x over time.deltatime and the speedchangerate.

If we don’t press in a direction, make it 0.

Same thing for Z and then set those to the float values.

Now you will blend vs snap into the animation state.



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
Al Heck

Unity Developer and Software Engineer who loves making games with GameDevHQ