GMS 2 Vertical (vsp) Moving Platforms


Finishing off my moving platforms for my project and this one is really giving me a headache.

I have a vsp platform but my player object keeps cliping/falling through it when the platform goes up after hitting a wall. On top of that the game freezes, not crashes, no doubt due to the while statement in the code.

Any help is appreciated.

else if (vsp_final != 0 && place_meeting(round(x),round(y+vsp_final),_wall_vsp))
   if (place_meeting(round(x),round(y+vsp_final),_wall_vsp))
       y += sign(vsp);
       vsp = 0;
Note that the vsp platform contains collision to reverse its speed and that works fine.


The way I do moving platforms (which has worked well so far): I have platforms perform their movement in Begin Step, so they all have moved before player is handled in normal Step. Each platform checks if player is riding them (collision at position y - 1, player is not falling or jumping). If so, the platform adds its own movement to variables on player that track this (call them external_hspd and external_vspd or such). When player Step event runs, controls are read as normal and vspd / hspd are calculated normally, but the external ones are added to them before collision checks start. This way, the collisions receive the total movement player has acquired during the step. At the end of the step the external tracker variables are set back to zero.

There are other ways, such as turning your movement code into generic script that receives instance id and hspd / vspd on call, and performs movement & collision checking. You can then call the function as many times as needed as various influences need to reposition player (or any other entity).