- Home /
How do I script the movement and set up the transition of my Mecanim Blendtree?
I have a left and right sidestep animation blended with a walk forward animation in a 2D blendtree. That is working fine. What I don't understand is how to make a transition to this from the default Idle animation state and also how to script the input.
I have three parameters in the Animator: Speed, VelocityX, and VelocityZ. The transition from Idle to the Movement blend tree is Speed > 0.1 Here is my script which doesn't work:
public class PlayerControllerScript : MonoBehaviour {
Animator anim;
// Use this for initialization
void Start () {
anim = GetComponent<Animator>();
}
// Update is called once per frame
void Update () {
float move = Input.GetAxis("Vertical");
float sidestep = Input.GetAxis("Horizontal");
anim.SetFloat("Speed", move);
anim.SetFloat("Speed", sidestep);
}
}
This is my very first time scripting with Mecanim and using blend trees, so obviously I'm pretty confused. Any advice at all is greatly appreciated.
Alright, I think it's better to incorporate the Idle animation into the $$anonymous$$ovement blend tree, so no transition is required.
I'm still very confused on how to get my script for the input to work, though. Any advice there?
There is a mistake in the following;
anim.SetFloat("Speed", move);
anim.SetFloat("Speed", sidestep);
You set "Speed" to sidestep only by this way, move is never used on practice. Apart from this, I'm not sure what are VelocityX and VelocityZ, but it seems you need to set up a transition from Any State to Idle for speed below 0.1, the same way between Idle and $$anonymous$$ovement.
VelocityX and Z are used in the 2D blend tree to blend the left and right side step animations with the walk forward animation
Here's a screen of my blend tree, if it helps explain what I'm trying to do. It works fine in the preview, I'm just having a hard time understanding just how to get it to do that with input in-game: