• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Dynamic jumping in a 2d platformer

J

Just a guy

Guest
Is there a way to stop adding vertical speed to a player when they reach a certain height or let go of the jump key at a certain time? (sorry I'm not good at talking. I mean holding down the jump key to go higher) I was thinking of something like super meat boy, hollow knight, or... really any 2d platformer. What should I use to accomplish this? My code watered down is basically if you are touching the ground, and you press space, vsp = -11. I am also using if keyboard check pressed for the jump key.
 
C

CreatorAtNight

Guest
Sorry, I totally misread your question, I removed my answer to save confusion. :p
 
Last edited by a moderator:

Slyddar

Member
This is Shaun Spalding's method and seems to work the best. You'll need to reset jumps to 1 when back on the ground.
Code:
//create event
jump_spd = 10;
jumps = 1;

//step event
//get input
jump = keyboard_check_pressed(vk_space);
jump_held = keyboard_check(vk_space);

//jump
if jump and jumps > 0 {
  vsp -= jump_spd;
  jumps -=1;
}

if vsp < 0 and !jump_held vsp = max(vsp, -jump_spd/2);
 
Top