How do I create a jump

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Hakim

2D game
I mean if it’s a slight press of a button it’s a small jump
Or if it’s pressed hard it’s a big jump

:bust_in_silhouette: Reply From: godot_dev_

Here are a couple ideas.

  • A jump squat based approach that counts the amount of time the jump button is pressed during the jump squat
  • An approach that does not require jump squat that will decelerate the upward momentum upon releasing the jump button

Jump Squat approach

  • You add a jump squat to the jump animation so that there is a delay between the start of the jump animation and the moment the player actually bounces up (they stay in place briefly and then jump) . You then measure the time the player is holding down jump during the initial jump delay of the jump squat. When the 2nd part of the jump animation starts (wait for the jump squat to end), then you dynamically adjust the jump height based on amount of time the jump button was held
  • Pros
  • You have a lot of control on how height the jump can be as the player (similar to Super Mario World, as opposed to smash bros where you can only short hop or full jump (nothing in between))
  • Cons
  • Given the jump squat requirement, jump may feel stiff if the jump squat takes too long; and if you make a short jump squat duration (like 2- 3 frames), then the player has very limited time to adjust the jump height

Releasing jump to decelerate jump

  • in this approach, the player holds jump, and the longer jump is held the higher the player goes by avoiding the jump-button-release decceleration. So whenever jump is released, you would applpy some downward acceleration to slow down the upward momentum
  • Pros
  • No need for jump squat delay, so jump can feel quite responsive
  • There is way more of a window to control the jump height so it won’t require strict timing by the player
  • You have a lot of control on how height the jump can be as the player (similar as jump squat)
  • Cons
  • I think it may be more tricky to implement compared to jump squat (just gravity + upward velocity) since applying velocity to negate a jump may feel jarring to a player if done incorrectly (if its not smooth) (requires gravity, upward velocity, and smooth accelerating downward velocity to counter act the jump)