Animating my snowboarder

I wanna animate my snowboarder when he is jumping. Currently my code looks like this

private void OnCollisionEnter2D(Collision2D other) {
        if (other.collider.tag=="Ground"){
           myAnim.SetBool("isGrounded" , true);
        }
    }

    private void OnCollisionExit2D(Collision2D other) {
        if (other.collider.tag=="Ground"){
            myAnim.SetBool("isGrounded" , false);
        }
    }

The problem is that it plays the animation every milisecond the player is not touching the ground so it looks like he’s having a seizure.

I want it so that the animation plays only when the player has covered a certain distance in the y direction. How do i approach the problem?

The animation continues to play until the player is grounded again. One way would be to turn looping off, then it will play once and stop until the player has landed again. If you want it to play more times, I think you can change the boolean to a trigger and then set exit time to 2 or 3 to have it play 2 or 3 times before returning to the previous (grounded) state. If you want it to stop at a specific height, you’d probably need an intermediate animation and state for when the player is in the air, but no longer being animated. Then you’d switch from the ‘not grounded’ animation to the intermediate state and then back to whatever state the grounded animation state is once it’s grounded

no thats not what i meant. I mean since the ground has a lot of irregularities the player gets launched up in the air alot of times and everytime it does that, the animation starts. Ive already turned looping off, thats not the issue.
I want the player to play the animation when, say, its 20 units above the ground and not 0.001 units above it

What is “the ground”? And what is “20 units above the ground”?

Maybe add a larger trigger collider around the player and use OnTriggerExit2D. Have you already tried that?


like this.

And this is what I meant:

As you can see, the trigger collider (red outline) touches the ground at the top sketch, and it does not touch the ground at the bottom sketch.

The game is not the real world. You may fake things to make your ideas work.

ohh thats clever… I’ll try it out. Thanks

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms