Windows Player slowly fall through platform

Hi, I've got another problem with my game, I've successfully add delay to the state change, but now I'm facing a new problem

I'm trying to make my platform moving from left to right. Therefore, I have 2 type of floor here 1 is floor and 2 is platform.

I have implement everything about the moving platform. However, when I tried to copy the code for collision between player and floor to the platform, the result is somewhat different.

Everytime a player land on the platform, they slowly fall through it. This doesn't happen when player fall on the floor or walls though

The code is nearly exactly the same, so I don't see any problem here, but I think there must be something going on in the collision code that override each other and make it glitchy.

Can you help me look through it and stop the player from falling through the platform?

in step event of player
GML:
#region //movement and collision with platform


key_left = keyboard_check(ord("A"));
key_right = keyboard_check(ord("D"));
key_jump = keyboard_check(ord("W"));

var move = key_right - key_left;
horispd = move*walkspd;
vertspd = vertspd + grav;
#endregion


#region // collision with floor

if ((place_meeting(x,y+1,Obj_floor)) || (place_meeting(x,y+1,Obj_platform))) && (key_jump)
{
    vertspd = jumppower;
}

if (place_meeting(x+horispd,y,Obj_floor))
{
    while (!place_meeting(x+sign(horispd),y,Obj_floor))
    {
        x = x + sign(horispd);
    }
    horispd = 0;
}
x = x + horispd;

if (place_meeting(x,y+vertspd,Obj_floor))
{
    while (!place_meeting(x,y+sign(vertspd),Obj_floor))
    {
        y = y+sign(vertspd);
    }
    vertspd = 0;
}
y = y + vertspd;

#endregion

#region //collision with platform
if (place_meeting(x+horispd,y,Obj_platform))
{
    while (!place_meeting(x+sign(horispd),y,Obj_platform))
    {
        x = x + sign(horispd);
    }
    horispd = 0;
}


if (place_meeting(x,y+vertspd,Obj_platform))
{
    while (!place_meeting(x,y+sign(vertspd),Obj_platform))
    {
        y = y+sign(vertspd);
    }
    vertspd = 0;
}

#endregion


#region //it not it

if (it = true)
{
    image_index = 0;
    walkspd = 6;
}
else
{
    image_index = 1;
    walkspd = 4;
}

#endregion
 

Rob

Member
how will i solve this? I still don't c how the y is increase
You want to do collision checks for everything on the y axis before having the " y = y + vertspd; " line.
If you check for collision with one object, dont find a collision, and then move the player down, and then check for collision with a different object, you'll get the problem you're describing.

  • Resolve collision with ALL objects
  • Add to y
 
Top