• Hey! Guest! The 37th GMC Jam will take place between May 28th, 12:00 UTC and June 1st, 12:00 UTC. Why not join in! Click here to find out more!

Platformers Part 2 - Quick Sand, Wall Jumping, Gliding

B

Blakkid489

Guest
Subscribed :D

EDIT: My main problem is with double jumping allowing the player to fall off the plat and jump in mid air.
 

GMLWaffle

Member
Subscribed :D

EDIT: My main problem is with double jumping allowing the player to fall off the plat and jump in mid air.
Ah glad you said something about that! I've recorded part 3, and it came out a bit longer than I had wanted it to, so unfortunately I wasn't able to fit it in part 3, however it will be first priority in part 4! But for the sake of you getting an answer quickly, how exactly are you trying to set it up?

the best way would be to create a Boolean variable called dblJump = false in the create event, then in the step event check for this:
Code:
if (!place_meeting(x,y+1,con_wall)) && !dblJump {
    dblJump = true;
}

if (dblJump) && (jumpKey) {
    vsp -= jumpspeed;
    dblJump = false;
}
this will check for collision below you, and if there is none, set dblJump equal to true, then if it's true it will allow you to jump once before resetting itself back to false.
 

GMLWaffle

Member
Ahhhh okay you don't want him to be able to jump after walking off a platform xD alright so to fix this it's kind of a similar process to the code I shared before, however we're going to set it up to say if the player has already jumped, then dblJump = true.

So here's our create event:
Code:
dblJump = false;
dblJumpCount = 2;
and here's what we're adding to the step event:
Code:
//dblJumping
if (place_meeting(x,y+1,con_wall)) && (jumpKey) && (!dblJump) {
    dblJump = true;
} else if (place_meeting(x,y+1,con_wall)) && (dblJump) {
    dblJump = false;
    dblJumpCount = 2;
}

if (dblJump) && (dblJumpCount >= 1) {
    if (jumpKey) {
        vsp = jumpKey * -jumpspeed;
        dblJumpCount -= 1;
    }
}
this will set our dblJump variable to only be true if we've jumped directly off of the wall controller object. This also puts a limit to the number of double jumps you get, in this case the variable is set to two, but you really only get one extra double jump. Hope this helps!

EDIT: btw, nice video response!
 
B

Blakkid489

Guest
Awesome. I got it now. I was using the dblJump in the wrong way. Tahnaks a bunch. looking forward to more videos. I've already shared your channel around :D
 
M

Mister Bread

Guest
Hey, great tutorial! Quick question about the wall jumping.

Is there any way to limit the wall jumping so you can't "climb" the walls by pressing the jump key several times?

I tried combining the double jump code from your other video with the wall jump code, but it didn't seem to work. Any suggestions?
 

GMLWaffle

Member
basically the same thing as the double jump code, but instead of checking for collision the second time with the object below you, check for collision with the wall to either side of the player. so if (!place_free(x-5,y) && !place_free(x+5,y) then do the jump. If this doesn't help, I'll work on a script for you tomorrow as it's rather late here.
 
M

Mister Bread

Guest
Wow, quick response! Thank you.

I messed around with the code a bit before I rechecked the forum and this is what I came up with. It seems to work as intended...

Code:
//Wall Jump

if (key_jump) && (place_meeting(x+1,y,obj_wall) || place_meeting(x-1,y,obj_wall) && (!doublejump))
{
    doublejump = false;
    doublejumpcount = 1;
    vspd = -jumpspeed;
}
and combing this with the double jump code...

Code:
//Double Jump
if (place_meeting(x,y+1,obj_wall)) && (key_jump) && (!doublejump) {
    doublejump = true;
} else if (place_meeting(x,y+1,obj_wall)) && (doublejump) {
    doublejump = false;
    doublejumpcount = 2;
}

if (doublejump) && (doublejumpcount >= 1) {
    if (key_jump) {
        vspd = key_jump * -jumpspeed;
        doublejumpcount -= 1;
    }
}
This way when colliding with the wall object, it'll set the doublejumpcount to 1 and only allow a second jump.

Haven't noticed any issues while quickly testing it. Do you think this is a decent solution? Still getting used to GML and hope this is sound coding.
 

GMLWaffle

Member
Wow, quick response! Thank you.
Code:
//Wall Jump

if (key_jump) && (place_meeting(x+1,y,obj_wall) || place_meeting(x-1,y,obj_wall) && (!doublejump))
{
    doublejump = false;
    doublejumpcount = 1;
    vspd = -jumpspeed;
}
This way when colliding with the wall object, it'll set the doublejumpcount to 1 and only allow a second jump.

Haven't noticed any issues while quickly testing it. Do you think this is a decent solution? Still getting used to GML and hope this is sound coding.
pretty well! Almost identical code to the double jump, which does virtually the same thing! (I would have posted code myself, but I've been busy sharing a Liquid Physics example all over the place).

Hope I was at least of some help!
 
M

Mister Bread

Guest
Only issue I'm just noticing is that the place_meeting(x+1) code doesn't seem to be working... I have a room with walls on the left and right, and the left wall works fine with the code but the right wall doesn't...

I'll try your idea and see if that works any different.


EDIT :

I edited the code line to replace the || with && and it seems to have worked.

Again, thank you for your quick reply and the help! I'll be looking forward to more of your tutorials as they're incredibly quick and concise.
 

GMLWaffle

Member
Only issue I'm just noticing is that the place_meeting(x+1) code doesn't seem to be working... I have a room with walls on the left and right, and the left wall works fine with the code but the right wall doesn't...

I'll try your idea and see if that works any different.
let me just open up the project file for these tutorials, and i'll write something up quickly

EDIT: to no luck tonight, I'll have to spend more time on it tomorrow
 
Last edited:
C

carzo

Guest
Hello Mr GMLWaffle.

Firstly: Thank you very much for doing this tutorials series.

I have adapted your quicksands script to my movement with aceleration engine.

I have a question:

Why do you need to create an alarm?

Some guy asked the same in the YouTube comments but I don't understand your reply. Mine works perfectly without an alarm.
 
Last edited by a moderator:
E

Ezeeskillz

Guest
Hey there,

First and foremost thank you for the excellent tutorials!!!

I had a question about changing something. I am using a combination of some of your code and some of Jordan Robinson's pixel perfect movement and collision code. So I have the following with k_glide being W.

//Jumping
speed_y += grav; //Apply gravity

if(k_jump && place_meeting(x, y + 1, con_solid))
{
speed_y = -6;
}

//Gliding
if (!place_meeting(x,y+1,con_solid)) && k_glide
{
grav = 0.06;
}
else if (place_meeting(x,y+1,con_solid))
{
grav = 0.2;
}


scr_collision();

How would I go about changing this so that if I am on the ground and I am holding W then when I jump my player object does a sort of super jump. How would I make it so that when I press W to glide it will slow my fall and not speed up my rise?
 
I

ItsMeIvan

Guest
when do you get into walk & jump animations, i just want to make a basic Mario platformer
 

Kaplah

Member
I'm enjoying your series so far. Quick question for you. How about a future episode covering rooms larger than the viewport? Sort of like any mario game, metroid, castlevania, etc? So far all demos and tutorials I've seen are on single screen platformers that fit in the view.

Watch I'll post this and my question will be answered in your third video.
 
Top