2D jump: animation time, jump height and wall collision

Hi all,

I’m doing some tests on a 2D project and atm I found 2 problems:

Problem 1:
I created a sprite animation of the jump, but now I see that if I jump off a platform higher than the standard jump the animation restart. How I can adjust the timing of the animation automatically take the jump duration? I can do this in one animation or I’ve to split the animation in 3 trunks: ascending time animation, max jump standing animation, falling time animation?

Problem 2:
I use a simple way to jump:

  • In the player object I’ve got a collider that chenge the value of a variable (called grounded) to true of false;
  • In the player I’ve got a C# code that in the Update() check if the player is grounded and if the key pressed is “Jump” and then apply some force to the player rigidbody;

(the source I followed was this: Unity 5 2D Platformer Tutorial - Part 4 - Jumping and Ground Check fixing. - YouTube)

The problem is that if I spam the Jump key it happens that sometimes the player jump higher than the usual. I found this:

And I think that is the problem as mine but I wanto to know if the rigidbody+kinematic thing is the right solution for this.

Problem 3:
As everyone I found the problem when I jump near a wall, keep pressing directional key, and the player stick to the wall. I created the non-frictional material, added to the wall and all is ok BUT the obviously problem is that the player if run over the top side of the square that make a wall the friction is 0 so I’ve to ease the speed: is this the only solution? Or I’ve to use two kind of square object: one for vertical walls (with no-frictional material) and one for the ground (without no-frictional material)?

Thanks in advance

Problem 1: You don’t need to create 3 separate trunks. Just uncheck the Loop Time on your Animation Clip.

Problem 2: Instead of Addforce, try using:
float HeightOfJump; rb2d.velocity = new Vector2 (0, HeightOfJump);

Hope it helps.

@yukuai

Hi Lawr.cincoarte,

1: if I unchek the loop the animations doens’t loop (ok) but if I make the player jumping with different force during the game the animation will be not syncronized with the jump. I mean: if the animation is 1.2 second long (0.5s for the animation of the ascending, 0.2s for the standing, 0.5s for the descending) and this work well with the actual jump power (that make the jump duration 1.2s long) if I add force to the jump making it 2s long the animation will run for 1.2s and then last with the last sprite in the animation for 0.8s.

2: I’ve to try it, thanks!

For problem 1 you just need to make it so that when he isn’t touching the ground the jump animation is playing and when he is back on the ground it goes back idle.