• 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 [SOLVED!] One way platformer collision (jump thru platform)

K

KilgoreT

Guest
So using bits and pieces of the rough platformer code you can find on youtube, I've managed to make one way platforms using the following code:

Code:
var vcollide;
vcollide = instance_place(x,y+vspd,oSolid);
if (vcollide != noone)
{
    if ((vcollide).type ==1)
    {
        while (!place_meeting(x,y+sign(vspd),oSolid)) y+=sign(vspd);
        vspd=0;
        grounded = 1;
    }
    if (((vcollide).type ==2) && (bbox_bottom) < (vcollide.bbox_top))
    {
        
        
            while (!place_meeting(x,y+sign(vspd),vcollide)) && (bbox_bottom) < (vcollide.bbox_top)
            y +=sign(vspd);
            
            vspd=0;
            grounded = 1;
        
    }
}
else grounded = 0;
y += vspd;
Now the issues I'm having concern what happens when the player is touching the pixel-wide jump-thru platform but not above it. What happens is that when my jump isn't high enough to clear the platform (jump is released early), even if the tippity top of my characters head is through the platfform, he will be sucked up above the platform at a slow speed. His sprite also changes to the idle "not jumping" sprite. I assume this has to do with the pixel checks (sign(vspd))?

Code:
if (key_jump && OnGround)
    {
    vspd = -jumpspd
    }
    else if key_jump_released
        {if vspd < 0
            {vspd *= .25
            }
I also understand there's probably some inefficiencies in my code, and my experiments with bbox are evidence of trying to fix the problem already, but any tips or pushes in the right direction are appreciated.
one way.png
 

TheouAegis

Member
I think you mean 1 px high, not wide.

Put in the player's GUI Draw Event:

draw_text(0,0,grounded);

When you cause the slow-rise issue, is it 0, 1 or rapidly alternating between both?

I'm kinda surprised you're having the issues you're having, considering you have the bbox_top vs. bbox_bottom check in there.

I'd personally change the collision code as follows:

Code:
var vcollide;
vcollide = instance_place(x,y+vspd,oSolid);
if (vcollide != noone)
{
   if ((vcollide).type ==1)
    {
        while (!place_meeting(x,y+sign(vspd),oSolid)) y+=sign(vspd);
        vspd=0;
        grounded = 1;
    }

    else

    if (((vcollide).type ==2) && vspd > 0 && (bbox_bottom) < (vcollide.bbox_top))
    {
      
      
            while (!place_meeting(x,y+sign(vspd),vcollide)) && (bbox_bottom) < (vcollide.bbox_top)
            y +=sign(vspd);
          
            vspd=0;
            grounded = 1;
      
    }
}
else grounded = 0;
y += vspd;
 
K

KilgoreT

Guest
Boy those additions made all the difference? My cowboy now consistently jumps through and lands on the platforms. Thank you so much! That bit about drawing the value to see whats happening will be something I keep in mind for all future bugs.
 
C

carzo

Guest
I am having the same problem than the original poster, even with theouAegis code.

I did the GUI draw event thing and it shows "0" while being sucked up and blinking from 0 to 1 while on ground.

Help please !
 
Last edited by a moderator:
Top