Log In  


Hi, im new to programming games and i've been watching tutorials and want to make an endless runner but i can't get to find a clear tutorial to follow on how to make a character jump, if somebody knows one or can help me to add the jumping to the character would help me a lot.



1

It depends on how you want the runner to feel. If your jump is simple, with the character jumping the height every time, that will give your game a simpler feel or possibly a punishing feel. If you want the player to have some control over jump height, that will make the game feel more modern and player-friendly. There's other possibilities too, but they're not as good for beginners.

In the simple case, define an amount of gravity, preferably in a spot you can find it easily, so that you can tweak it for feel. The number should be smaller than you expect because graviy is an acceleration, not a speed. Then, every update, check if the player is on the ground in whatever way makes sense for the tutorials you've been reading, and set an upward speed for the character. This probably means a negative number in a variable like "dy" or "vert_move". If your character isn't on the ground, add gravity to the character's speed. Finally, change the character's position by the character's speed.

In pseudocode:

  if player_on_ground() then
    if jump_input() then
      player.dy = -jump_speed
    end
  else
    player.dy += gravity
    player.y += player.dy
  end

In the case where the player is allowed to choose their jump height, I've found the best way to handle that is to add another amount similar to gravity every frame after the player either reaches the maximum height or lets go of the button. If you also check for the jump button being released at least once between jumps, that also helps with making sure the character jumps specifically when the player wants.

In pseudocode

  if not jump_input then
    player.jump_released = true
  end
  if player_on_ground() then
    if jump_input and player.jump_released then
      player.dy = -jumpspeed
      player.jump_released = false
    end
  else
    player.dy += gravity
    if (not player.jump_released) player.dy += extra_gravity
    player.y += player.dy
  end

thanks i was looking to give the player more control when they jump like how much time they hold the x button, so in both cases i have to set up gravity right?

right now i only have this done i still can't make the character jump and is driving me crazy lol

Cart #fekapopina-0 | 2025-07-18 | Code ▽ | Embed ▽ | No License



[Please log in to post a comment]