# Approach for Blend Trees without the use of Rigidbodies

I have a bipedal boss in my game that’s moving around the arena using A * Pathfinding, and I want to use a Blend Tree to allow his walk animation to show movement to the right/left/etc. To do this, I’ve made the blend tree be 2 dimensional and calculated the velocity in the x and z directions by doing the following calculation in update:

``````           if (previous != null)
{
currentVelocity = (transform.position - previous) / Time.deltaTime;
animator.SetFloat("Blend", currentVelocity.x);
animator.SetFloat("Blend2", currentVelocity.z);
}
previous = transform.position;
``````

Am I approaching this correctly? I’m new to Blend Trees, so my confidence isn’t so strong.

Here’s my blend tree for reference. I’ve got my idle animation in the middle, and my animations for forward-left, forward-right, etc in what I believe to be the right places to track with this setup.

The code looks correct. Should output the same results as Rigidbody.velocity would (velocity in units per second). Does the result behave as you want?

You’re not approaching this correctly, because your character can turn, and you are specifying absolute velocity. The parameters should be relative to character’s left/forward. Additionally, you need either 4 or 8 blended animations in addition to idle for a character movement, currently you have six, and you’re missing “walk left” and “walk right” animations.

If “previous” is a Vector3, then it is a struct, and it cannot be null.

Instead of calculating velocity based on position, you should either take velocity stored in a rigidbody, OR use player inputs.

I admit that I missed the fact that the vector should be in local space instead of world space. Can be fixed with Transform.InverseTransformDirection command

``````currentVelocity = this.transform.InverseTransformDirection(currentVelocity);
``````

However, nothing wrong with using a formula for velocity instead of Rigidbody.velocity (provided you convert it to local space). If you are using built in pathfinding, you can also use NavMeshAgent.velocity. (I think player inputs are non-option since it is supposed to be an NPC)