1. Hello Guest! It's with a heavy heart that we must announce the removal of the Legacy GMC Archive. If you wish to save anything from it, now's the time! Please see this topic for more information.
    Dismiss Notice

GMS 2 Jump Through Platforms

Discussion in 'Programming' started by JeanSwamp, May 9, 2019.

  1. JeanSwamp

    JeanSwamp Member

    Joined:
    Jan 11, 2018
    Posts:
    131
    So today I was trying to fix something that I've been delaying for a long time, and I actually managed to fix it.

    Now the problem is, somehow I managed to mess up and forgot what was the thing that I had to change in order for it to work.

    The problem I'm having is this:

    When standind on top of a jumpthrough platform, if I overlap with anotherone, it will cause the player to fall.

    This is how the code looks like:

    Code:
    var vcollide;
    vcollide = instance_place(x,y+vsp,oJumpTh)
    if (vcollide != noone)       
    {
        if (bbox_bottom < vcollide.bbox_top) && !(state == states.ladder) && !downready
        {
            if (!place_meeting(x,y,vcollide))
            {
                while (!place_meeting(x,y+sign(vsp),vcollide))
                {
                    y = y + sign(vsp);
                }
            vsp = 0;
            }
        }
    }
    Playing around today I changed some stuff and I managed to fix it, somehow I'm stupid and must have undo it.

    Everything else is working just fine.

    Hopefully someone can point me out the mistake
     

    Attached Files:

  2. Timothy

    Timothy Member

    Joined:
    Aug 7, 2016
    Posts:
    64
    You simply need to check ALL jump through platforms you are colliding with. For each one, if previously above it, snap to the top of the platform. Collision event is great for things like this. GMS really needs a collision function that returns an array of instances.
     
  3. TheSly

    TheSly Member

    Joined:
    Jan 16, 2017
    Posts:
    1,000
    How about instance_place_list?
     
    Timothy likes this.
  4. Timothy

    Timothy Member

    Joined:
    Aug 7, 2016
    Posts:
    64
    Nice, didn't know they added that.
     
  5. JeanSwamp

    JeanSwamp Member

    Joined:
    Jan 11, 2018
    Posts:
    131
    I was toying around with instance_place_list before writting this post but couldn't get it to work
     
  6. jonjons

    jonjons Member

    Joined:
    May 10, 2017
    Posts:
    298
    I can give you a way that i use to check in witch platform the entity is walking on... is works for both player and enemies, and they can jump trow platforms.

    paste this code right at the beginning of the step event
    Code:
    var check =    collision_circle(x, y+17, 3,  obj_Platform_Rotation, 0, 1); //
    var check2 = collision_rectangle(bbox_left, bbox_top, bbox_right, bbox_bottom-1, obj_Platform_Rotation, 0, 1); //-obj_Platform_Rotation is the platform the entity can jump trow
    
    if ( check != noone && check != check2 && platGo == 0 && vsp >= 0 )
    {
        wallWalk = check;
    }
    else
    {
        wallWalk = obj_wall_Parent; //-obj_wall_Parent is a solid wall and parent for rotation wall
    }
    
    //------------//-----//-----
    //------//--GOING-THORW-PLATFORMS--//--------------------------------
    if (  key_Down && platGo == 0)
    {
        platGo = 0.5;
    }
    if (platGo > 0)
    {
        platGo -= room_speed/1000;
        platGo = clamp(platGo, 0, 1);
    }
    
    

    in the create event
    Code:
    wallWalk = obj_wall_Parent;
    platGo = 0; //--GOING-THROW-PLATFORMS--

    Its important that you know whats happening in the draw event paste this code
    Code:
    draw_text(x-30, y+100, "wallWalk " + string (wallWalk));
    draw_rectangle(bbox_left, bbox_top, bbox_right, bbox_bottom-1, 1);
    draw_circle(x, y+17, 3, 1);
    

    When the small circle touches the platform below, and the bbox square is not inside the wall and platGO is less or equal to zero that platform becomes active... else the entity will fall trow the platform.

    heres a video of how its working... the platforms tickness are the minimum of 16 in height... has you see in the step event (( var check = collision_circle(x, y+17, 3, obj_Platform_Rotation, 0, 1))) the y+17 leaves only 1 pixel of gap its should be very precise.
     
    Last edited: May 14, 2019

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