Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length

 
Advanced search

1075932 Posts in 44152 Topics- by 36119 Members - Latest Member: Royalhandstudios

December 29, 2014, 04:13:46 PM
TIGSource ForumsDeveloperTechnical (Moderators: Glaiel-Gamer, ThemsAllTook)Mario Style Jump
Pages: [1]
Print
Author Topic: Mario Style Jump  (Read 392 times)
Rat Casket
Level 10
*****


i can do what i want

TheRabbitInferno
View Profile WWW Email
« on: March 14, 2013, 07:22:26 AM »

Just as the title says. How would one make a jump that increases in height as the button is pressed, and has a shorter jump when the button is just tapped?

I understand the logic behind it but I'm not sure how to translate that into code.

Current jump code:
Code:
if (jump) && (onGround){
     ySpeed = -10;
}else{
     ySpeed += gravSpeed;
}

Now this works just fine for a set jump height but I'm not sure what needs to be tailored to do a Mario style jump.
Logged

Ant
Guest
« Reply #1 on: March 14, 2013, 07:28:05 AM »

You reduce the vertical speed when the button is released. So something like:

Code:
if keyboard_check_released(vKey_Jump) and vspeed < 0 {vspeed /= 2;}
Logged
Rat Casket
Level 10
*****


i can do what i want

TheRabbitInferno
View Profile WWW Email
« Reply #2 on: March 14, 2013, 07:31:25 AM »

Ah, so will I need to change my jump code from keyboard_check(button) to keyboard_check_pressed(button) ?
Logged

Ant
Guest
« Reply #3 on: March 14, 2013, 07:54:40 AM »

Yeah the initial jump code should really only be on the keyboard_check_pressed. The regular keyboard_check returns true every single step if the key is pressed, probably won't make much difference in your case but best to be on the safe side to avoid bugs later on.
Logged
Rat Casket
Level 10
*****


i can do what i want

TheRabbitInferno
View Profile WWW Email
« Reply #4 on: March 14, 2013, 02:45:11 PM »



*success*
Logged

Fallsburg
Level 10
*****


Fear the CircleCat


View Profile
« Reply #5 on: March 15, 2013, 06:26:38 AM »

Little bit redundant since you figured it out, but here's a good page on exactly what is going on behind the scenes with Mario's jumping.

I will say, instead of just reducing speed, here is what I do.

Code:
gravity = default_gravity
if JUMP_PRESSED && vy > 0  //Assumes up is positive y
   gravity *= gravity_reduction_factor

vy -= gravity*dt

y = vy*dt

This only allows the player to control the height of the jump on the way up (instead of allowing them to control gravity on the way down as well [which feels wrong if they can slow down gravity after falling off of something]).
Logged
Rat Casket
Level 10
*****


i can do what i want

TheRabbitInferno
View Profile WWW Email
« Reply #6 on: March 15, 2013, 06:39:13 AM »

That is pretty awesome. I haven't really played Mario in... years so I totally forgot about that. Awesome article and I'm going to test out this code of yours.

What is limiting the height of the jump there?
Logged

Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic