• 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!

Legacy GM Dropping of a ledge. [solved but open to discussion]

S

Sudo_Radish

Guest
Hi all.

I am currently in the middle of making a C64 style retro platformer. I have been following Shaun's tutorials and I have included the code to detect inclines. I intend to use this for stairs in the game. However I am finding that when the player character drops from a ledge there is a split second where the player can correct and return back onto the ledge. Also when the player jumps up to a ledge the character is almost launched a bit further.

I will include the code that I have got in my character object.

Code:
//Get the player's input
key_right = keyboard_check(vk_right);
key_left = -keyboard_check(vk_left);
key_jump = keyboard_check_pressed(vk_space);

//React to inputs
move = key_left + key_right;
hsp = move * movespeed;
if (vsp < 10) vsp += grav;

if (place_meeting(x,y+1,obj_platform))
{
    vsp = key_jump * -jumpspeed
}

//Horizontal Collision
if (place_meeting(x+hsp,y,obj_platform))
{
    //Stairs detection
    yplus = 0;
    while (place_meeting(x+hsp,y-yplus,obj_platform) && yplus <= abs (4*hsp)) yplus += 1;
    if place_meeting(x+hsp,y-yplus,obj_platform)
    {
        //Standard collision detection
        while(!place_meeting(x+sign(hsp),y,obj_platform))
        x += sign(hsp);
        hsp = 0;
    }
    else
    {
        y -= yplus;
    }
   
}
x += hsp;

//Vertical Collision
if (place_meeting(x,y+vsp,obj_platform))
{
    while(!place_meeting(x,y+sign(vsp),obj_platform))
    {
        y += sign(vsp);
    }
    vsp = 0;
}
y += vsp;
My question is simple really. Is there a way of making it so that once the character drop from a ledge they cannot correct and fall? Or is this a limitation within GM:S that I am going to have to work with?
 

jo-thijs

Member
Hi and welcome to the GMC!

This is not a limitation of GM:S, but rather a consequence of your design.
You have specifically implemented a system that allows the player to climb up small ledges,
now you have a situation in which you want that to not happen.

The only way to fix this is to find out what this situation is exactly.

One way to identify this situation, is by recognizing that the player is not on solid ground,
whereas he is when climbing up stairs.
Using this, you can just simply insert:
if (place_meeting(x, y+1, obj_platform))
right before the while loop in your code.
 
S

Sudo_Radish

Guest
I have tried but for some reason it completely bugs out when I try to do that code. My next plan was to create a new stair object and then do a teleport to just above the stair object
 
S

Sudo_Radish

Guest
Don't you just love programming.....

Don't ask me why but when I replaced

while (place_meeting(x+hsp,y-yplus,obj_platform) && yplus <= abs (4*hsp)) yplus += 1;

with

while (place_meeting(x+hsp,y-yplus,obj_stairs) && yplus <= abs (4*hsp)) yplus += 1;

suddenly it works. And exactly how I want it to....

I thank beer for this.

I should point out that I made a new object called obj_stair and gave it a parent of obj_platform.
 
S

Sudo_Radish

Guest
I will post a video of it working when I finished the test room. It's been a headache. But a good headache
 
S

Sudo_Radish

Guest

This is the test video. Fell porud of myself that I got it working. Not touched game dev tools since the C64 and Amiga days.
 
S

Sudo_Radish

Guest
Going for a retro c64 style. So I am trying to work to the c64 limitations. From colour to sprite size and workable screen size. I then upscale 300% to make it playable.
 
Top