Few frames of animation gets skipped off

Hi,

I am having a jumping animtion of a character which animates smoothly while running on my “Animation” Window, but the same when tried to animate through script appears to be skipping off few frames thus making some kind of jerky animation.

Code :

void Update() 
{
   if(Input.GetKeyDown(KeyCode.UpArrow))
		{
			 StartCoroutine(DoJumpAnimation());
		} 
}

IEnumerator DoJumpAnimation()		
    {
	 m_charAnim.animation.CrossFade("jumping");
	 yield return new WaitForSeconds(m_charAnim.animation["jumping"].length); 
	}

Here if I press the UpArrow with some interval then it works fine, if at all I keep on pressing the key continuously then I get the problem in animation.

Anybody please help me to resolve my problem.

1 Answer

1

I’m not sure if this is going to work but… I think that the yield is preventing the animation to loop at certain period of time (jumping.length), but if you continue hitting the UpArrow, then you continue calling the function and it starts calling the animation before the previous one have ended…

IEnumerator DoJumpAnimation()     
{
     if (!animation.isPlaying("jumping"))
     {
           m_charAnim.animation.CrossFade("jumping");
     } 
}

You might need to leave the yield inside the function, but you might not need it with the if statement