Playing the jump animation twice, why?

Hi everyone.

In my script, I only have one place that mentions the jump animation.

        if(Input.GetButtonDown("Jump"))
        {	
            animation.CrossFade("jump");
            moveDirection.y = jumpSpeed;
        }

My problem is that when I press the space bar, which have the default value on the input button, it plays the animation twice.

why would that be?

Do you have the script attached twice?

It’s only on once. All of the other animation are playing correctly. Also i,ve looked in 3DS MAX and the animation only plays once with the frames that I’ve marked down.

Interesting. I don’t really have any ideas then, unfortunately.

I believe that you may be calling the jump animation because you are holding down the space bar, and your not telling the game that you have jumped.

Observe the Pseudo code:

var isGrounded=false;
function Update(){
// dont let us jump unless we are on the ground
if(Input.GetButtonDown("Jump")  isGrounded)
{	
animation.CrossFade("jump");
moveDirection.y = jumpSpeed;
// if we jumped, then we are no longer grounded
isGrounded=false;
}

// check to see if we are on the ground
if(checkToSeeIfWeAreGrounded()){
isGrounded=true;
}
}

Check over the 3rd person controller in the standard assets.

Thanks, bigMisterB, I will try it out.

Also try http://www.unifycommunity.com/wiki/index.php?title=Scripts look under “CharacterControllers” and find (DoubleJumpController).

Its for 2D games but maybe you can tweak it for your game.