3
votes

I'm currently activating a trigger parameter to cycle the jump animation using:

isGrounded is my 'is player grounded bool', which I'm using to determine wether or not my player is allowed to jump. I'm using a child player object and using Physics2D.lineCast(myPlayer, myPlayerGround, playerMask) to do so.

I'm triggering the jump animation (using a trigger parameter to transfer to the jump animation from the run or idle, which are the only 2 other animations I'm using which currently work flawlessly) using the spacebar, the same way I tap in to the y axis jump velocity.

I can't figure out a reliable way to reset the trigger. I tried resetting it if isGrounded returned true, but then I'm assuming I'm getting a false positive, as it will only trigger in the first place if isGrounded returns a true? I also tried triggering the animation on by running a check to see if isGrounded returns a false, but if that's the case, the jump animation will play if I fall off a ledge, as well as actually jumping, which of course doesn't make sense.

3

3 Answers

0
votes

I would put a couple of conditions, including the velocity direction and the isGrounded state. To reset the jump animation, you must be moving downward, and the isGrounded must be triggered.

0
votes

For perfect results in these kind of situation I always do trust on Delegates. You can use delegate such as your ground will through the message if players did land. Here I gave a detailed implementation of exactly same scenario. Have a look at my answer there.

0
votes

You must add conditions to your animations.

Animator.SetBool("isTouched", isTouched);

When you set new value, your animation will be animated. Take a look at this tutorial.