I have a HeroInput class that checks for tapping, holding or double tapping buttons. The checks are all done through Update. I’ve debugged with print to check that the inputs are being picked up correctly by that script.
However, the jump input seems to be getting inconsistently missed by my animator.
I use ‘GetButtonDown’ to find the specific frame to play the animation and apply the upward velocity. The velocities are being applied correctly by my HeroPhysics script, the character is lifting off. However, the Animator is failing to play the jump animation about 1 in 20 times.
I’ve checked print to confirm that jInput is set to 1 for only one update frame, so I can only assume that somehow the Animator is not getting an update on that frame.
Any ideas on how to fix this without holding jInput at 1 an extra frame or two? I’m still new to this so I won’t be surprised if I’m totally wrong about what’s happening.
Here is the relevant bit of script…
void Update ()
{
Animator anim = GetComponent<Animator>();
//Jump Input
if (Input.GetButtonUp("Jump")) //Stop Jump&Flight
{
jInput = 0;
}
if (Input.GetButton("Jump"))
{
if (Input.GetButtonDown("Jump"))
{
if (jCount == 1) //Fly
{
jInput = 3;
jCooler = 0.25f;
jCount = 2;
}
else //Jump
{
jInput = 1;
jCooler = 0.25f;
jCount = 1;
}
}
else
{
jInput = 2;
}
}
//jCooler Reset
if (jCooler > 0)
{
jCooler -= 1 * Time.deltaTime;
if (jCooler < 0)
{
jCooler = 0;
}
}
else
{
jCount = 0;
}
//Set animator param
anim.SetInteger("jInput", jInput);
}