GameMaker Collision with Moving Platforms

L

LCM

Guest
Hi!
So I'm working on a platformer and just finished programming moving plateforms. Problem is, especially with platforms moving up and down, my player object gets stuck in the platform and I can't move my player anymore.
Looking at my code, I guessed why it happens, but can't find a way to make it function. So I'd really appreciate it if someone could teach me how to do it!
Thanks for reading!

Here's the code:

GML:
if (place_meeting(x + hsp, y, obj_MovingPlatform))
{
    while (!place_meeting(x + sign(hsp), y, obj_MovingPlatform))
            {
                x = x + sign(hsp);
            }
    hsp = 0;
    hsp_frac = 0;
}

if (place_meeting(x, y + vsp, obj_MovingPlatform))
{

    while (!place_meeting(x, y + sign(vsp), obj_MovingPlatform))
    {
        y = y + sign(vsp);
    }
    vsp = 0;
    vsp_frac = 0;
}

if (place_meeting(x, y + sign(vsp), obj_MovingPlatform))
{
    with (obj_MovingPlatform)
    {
        other.x += hsp;
        other.vsp = vsp;
    }
}
 

TheouAegis

Member
First off, and most importantly,
with (obj_MovingPlatform) {
He just broke your game right there. by putting that code in, you can only have one moving platform and the entire room active at a time. You're going to need to find the ID of the platform the player is actually on using instance_* functions.

Second, you are forcing the platforms to maintain a steady, constant speed. You should use the end step event to update the player relative to the platform after everybody has had a chance to move.
 
L

LCM

Guest
Really? Worked just fine for me even with multiple platforms... Maybe I was just lucky haha
Anyway thanks for the answer, will try that later!
 

FrostyCat

Redemption Seeker
Really? Worked just fine for me even with multiple platforms... Maybe I was just lucky haha
If you had multiple moving platforms, then you would appear to stand on one moving platform, but your horizontal movement would be conducted by all of them playing tug-o-war on you, and your vertical movement conducted by all of them playing chicken on you.

Learn the difference between objects and instances and make it count. Until things like obj_MovingPlatform.x, if (place_meeting(...)) { with (other) { ... } } and if (place_meeting(xx, yy, obj_MovingPlatform)) { with (obj_MovingPlatform) { ... } } look immediately wrong to you, you cannot succeed with GM.
 
Top