- Home /
Mecanim animation and scripting problems
Hi everybody. I'm actually working on a fps/tps game and I have problem with setting up my character animation. Also, I'm using mecanim to do that. My problem is that when I start the game, my charater plays the stand and prone animations correctly, but when it comes to the crouch animations, it only play the forward animation. I am using a blend tree to go from stand, crouch and prone and I have 2d blend trees for stand, crouch and prone(Image reference). I searched everywhere for an answer but never found any solution. I am pretty sure the problem is in my script because i'm new to all this stuff. I also posted my script if the problem is in there. It would be very appreciated if you could try to help me out because I'm pretty much stuck here at the moment. Thank you in advance !
Script:
pragma strict
internal var animator : Animator;
private var x : float;
private var y : float;
private var t : float;
private var zero : float;
function Start ()
{
animator = GetComponent(Animator);
zero = 0.0;
}
function Update ()
{
x = Input.GetAxis("Horizontal");
y = Input.GetAxis("Vertical");
if(Input.GetKey(KeyCode.LeftControl))
{
t = -1.0;
}
else if(Input.GetKey(KeyCode.C))
{
t = 1.0;
}
else
{
t = 0.0;
}
animator.SetFloat("Transition", t);
if(t == -1.0)
{
animator.SetFloat("VelocityX1", x);
animator.SetFloat("VelocityY1", y);
animator.SetFloat("VelocityX", zero);
animator.SetFloat("VelocityY", zero);
animator.SetFloat("VelocityX2", zero);
animator.SetFloat("VelocityY2", zero);
}
else if(t == 1.0)
{
animator.SetFloat("VelocityX2", x);
animator.SetFloat("VelocityY2", y);
animator.SetFloat("VelocityX1", zero);
animator.SetFloat("VelocityY1", zero);
animator.SetFloat("VelocityX", zero);
animator.SetFloat("VelocityY", zero);
}
else if( t == 0.0)
{
animator.SetFloat("VelocityX", x);
animator.SetFloat("VelocityY", y);
animator.SetFloat("VelocityX1", zero);
animator.SetFloat("VelocityY1", zero);
animator.SetFloat("VelocityX2", zero);
animator.SetFloat("VelocityY2", zero);
}
}