My jump function is called twice.


6702478--769603--upload_2021-1-8_13-26-59.png
6702478--769606--upload_2021-1-8_13-27-16.png
I want my jump function to keep jumping while I hold down the button, but my function is called twice instead of once.

Check your IsGrounded(), maybe in the instant you jump you are still in contact with the ground.

You could:

  • place yourself afar from the ground contact, instantly.
  • disable the ground check for some small time or frames.
  • set the center of the collision shape a little above (so it doesnt collide) and them move it back.
  • use a different method to detect ground collision: raycast or another shape.
2 Likes

Put input checks in Update(), not FixedUpdate(). FixedUpdate can run multiple times per frame.
Also you’ll need to fiddle with whether to use GetKey() or GetKeyDown(), how fast you want to do repeated jumps (need a cool-down period maybe), etc.

1 Like

He’s using the new Input System and seems to have the input handling pretty much correct. I would say his main problem is this:

You need to set jump = false in your jumping code. This way the player’s intent to jump is only consumed exactly one time.

3 Likes

but I want when my Character hit ground if Space is hold to jump again… my problem is that when my character hit ground my Jump function is called twice.

Did you move it to Update()? FixedUpdate() could be the problem, as your IsGrounded() may not get set to false before another one is called.