1. Hey! Guest! The 34th GMC Jam will take place between August 22nd, 12:00 UTC (Thursday noon) and August 26th, 12:00 UTC (Monday noon). Why not join in! Click here to find out more!
    Dismiss Notice

GM:S 1.4 Dropping of a ledge. [solved but open to discussion]

Discussion in 'Programming' started by Sudo_Radish, Jun 25, 2016.

  1. Sudo_Radish

    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?
     
  2. jo-thijs

    jo-thijs Member

    Joined:
    Jun 20, 2016
    Posts:
    2,844
    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.
     
    Sudo_Radish likes this.
  3. Sudo_Radish

    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
     
  4. Sudo_Radish

    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.
     
  5. jo-thijs

    jo-thijs Member

    Joined:
    Jun 20, 2016
    Posts:
    2,844
    Ah well, glad the issue got solved anyway!
    Please, tag this topic as solved to indicate it is solved.
     
    Sudo_Radish likes this.
  6. Sudo_Radish

    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
     
  7. Sudo_Radish

    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.
     
  8. jo-thijs

    jo-thijs Member

    Joined:
    Jun 20, 2016
    Posts:
    2,844
    Interesting style you've got going on there, might become very cool!
     
    Sudo_Radish likes this.
  9. Sudo_Radish

    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.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice