GML Player Not Staying On Top of Vertical Moving Platform When Moving Upwards

Jamie572

Member
Hello! I've been attempting to create vertically and horizontally moving platforms for the small game project I'm working on. The horizontal platforms work perfectly; however, the vertical do not.

When the player jumps on to a vertically moving platform that is currently in an upwards motion, they simply fall through. If the platform is in a downwards motion, they stay on top without any glitchy movement.

I've attempted tweaking the following lines of code in my obj_player and obj_vertical_platform objects, which I believe to be the source of the issue, as well as changing the events in which they take place to Begin and End Step events.

Relevant code of obj_player's Step Event:
Code:
// Vertical Collision
if (place_meeting(x, y + vspd, obj_block))
{
    while(!place_meeting(x, y + sign(vspd), obj_block))
    {
        y += sign(vspd);
    }

    // Reset the variables.
    vspd = 0;
}
y += vspd;
obj_vertical_platform's Create Event:

Code:
sprite_index = -1;

// Initialize Variables
angle = 0;
angleIncrement = RADIAN; // Defined variable that is 0.0174532...
angleMultiplier = 1;
obj_vertical_platform's Step Event:
Code:
// Create motion.
angle += angleIncrement;
var vspd = sin(angle) * angleMultiplier;

// To avoid erroneous checking.
if (instance_exists(obj_player))
{
    // Checks if player is not above platform, and masks the platform appropriately.
    if ((round(obj_player.y + (obj_player.sprite_height / 2)) > y + vspd) || (obj_player.key_down)) mask_index = -1;

    else
    {
        // Give the object the appropriate mask.
        mask_index = spr_vertical_platform;

        // If in contact with player, set vspd_carry to vspd.
        if place_meeting(x, y - sign(vspd), obj_player)
        {
            obj_player.vspd = vspd;
        }
    }
}
// Increment y based upon vspd.
y += vspd;
I am currently using Game Maker: Studio 1.4.1772. I plan on porting my game to Studio 2 once I complete it. If any other code is needed, I will provide it upon request. A preemptive thank you for any and all help!
 

obscene

Member
This really doesn't do anything...

obj_player.vspd = vspd;

If you directly moved the player instead it should work...

obj_player.y+=vspd;
 

Jamie572

Member
This really doesn't do anything...

obj_player.vspd = vspd;

If you directly moved the player instead it should work...

obj_player.y+=vspd;
Technically, vspd is a variable that is simply added to y in the Step Event. However, with your modification, the player still falls through. Thanks for the tip, though.
 

obscene

Member
if place_meeting(x, y - sign(vspd), obj_player)

I'm too sleepy now to decided if this is right or not, but y minus the sign of the direction the platform is going... Just see if the player is above. Use some show_debug_message() calls in there that let you watch your compiler and determine at which point the failure is happening.
 

Jamie572

Member
if place_meeting(x, y - sign(vspd), obj_player)

I'm too sleepy now to decided if this is right or not, but y minus the sign of the direction the platform is going... Just see if the player is above. Use some show_debug_message() calls in there that let you watch your compiler and determine at which point the failure is happening.
Did you read through my code? I don't mean to sound rude -- I'm simply confused. That's in the Step Event of the obj_vertical_platform:
obj_vertical_platform's Step Event:
Code:
// Create motion.
angle += angleIncrement;
var vspd = sin(angle) * angleMultiplier;

// To avoid erroneous checking.
if (instance_exists(obj_player))
{
   // Checks if player is not above platform, and masks the platform appropriately.
   if ((round(obj_player.y + (obj_player.sprite_height / 2)) > y + vspd) || (obj_player.key_down)) mask_index = -1;

   else
   {
       // Give the object the appropriate mask.
       mask_index = spr_vertical_platform;

       // If in contact with player, set vspd_carry to vspd.
       if place_meeting(x, y - sign(vspd), obj_player)
       {
           obj_player.vspd = vspd;
       }
   }
}
// Increment y based upon vspd.
y += vspd;
Update:

It has to do with this line of code:
Code:
if ((round(obj_player.y + (obj_player.sprite_height / 2)) > y + vspd) || (obj_player.key_down)) mask_index = -1;
Modifying certain parts make it work...
 
Last edited:

obscene

Member
Did you read through my code? I don't mean to sound rude -- I'm simply confused. That's in the Step Event of the obj_vertical_platform:


Update:

It has to do with this line of code:
Code:
if ((round(obj_player.y + (obj_player.sprite_height / 2)) > y + vspd) || (obj_player.key_down)) mask_index = -1;
Modifying certain parts make it work...
Yeah the line I quoted was from that. I don't know if vspd is negative or positive, so I was curious as to whether that line even works correctly and detects the collision. Seems it would simpler to just check above the platform (y-1) instead. Personally I just ask "with (obj_player) if place_meeting(x,y+1,other)" and then move the player to follow the platform (before moving the platform).

Glad you narrowed it down but I don't what certain parts would mean so can't help clarify. But again, best way to solve this type of stuff is show_debug_message() or drawing values on screen. Check to make sure all the values match what you THINK they are, and check to see which sections of code run and which are skipped.
 

Jamie572

Member
Yeah the line I quoted was from that. I don't know if vspd is negative or positive, so I was curious as to whether that line even works correctly and detects the collision. Seems it would simpler to just check above the platform (y-1) instead. Personally I just ask "with (obj_player) if place_meeting(x,y+1,other)" and then move the player to follow the platform (before moving the platform).

Glad you narrowed it down but I don't what certain parts would mean so can't help clarify. But again, best way to solve this type of stuff is show_debug_message() or drawing values on screen. Check to make sure all the values match what you THINK they are, and check to see which sections of code run and which are skipped.
"vspd" is a changing variable that is both positive and negative. I'll try the place_meeting(x, y - 1...), next.

I wonder if I can retain the platforms' being able to be jumped through...
 
Top