GameMaker Movable platforms and inertia

M

Midastouch

Guest
Hello everyone,

I did a little piece of code, it works well but i have 1 problem.
When my platform change her direction my player on it continue his movement on some pixel, it looks like if he had some inertia (this inertia stay for 0.5 second no more, but it moves my player).
But the faster the platform moves, the greater the inertia is.

Even if this inertie moves my player just a bit, i want to fix it to that my player stay perfectly immobile on the platform.

Any ideas?

Code:
var input_horizontal = keyboard_check(key_right) - keyboard_check(key_left);


if(input_horizontal != 0) //when press move key
    {
    horizontal_speed += accel * input_horizontal;
    horizontal_speed = clamp(horizontal_speed, -max_horizontal_speed, max_horizontal_speed);
    }
else//when stop pressing move key
{
    if is_on_Hplatform = false//added this because without player move on platform
    {
    horizontal_speed = lerp (horizontal_speed, 0, friction_); //Returns the linear interpolation of two input values by the given amount
    }
}

///////////////////////////////////////////COLLISIONS WITH WALLS////////////////////////////////////////////////////////////////////
if(place_meeting(x + horizontal_speed, y, obj_Wall))
{
   while(! place_meeting(x + sign(horizontal_speed), y, obj_Wall))
       {
       x += sign(horizontal_speed);
       }
   horizontal_speed = 0;
}

x += horizontal_speed;
 
if(place_meeting(x, y + vertical_speed, obj_Wall)) {
     
       while(!place_meeting(x, y + sign(vertical_speed), obj_Wall)) {
           y += sign(vertical_speed);
     
       }
        vertical_speed = 0;
       }


////////////////////////////////////////////////////////////JUMPS////////////////////////////////////////////////////////////////////////////////////////

if is_on_solid = true //if you are on a platform for exemple
{
   if(input_jump != 0)
       {
       vertical_speed += jump_force;
       }
}
/////////////////////////////////////////////////HORIZONTAL PLATFORM/////////////////////////////////////////////////////
if(place_meeting(x, y + vertical_speed, obj_Hplatform))
   {
   while(! place_meeting(x, y + sign(vertical_speed), obj_Hplatform))
       {
       y += sign(vertical_speed);
       }
  vertical_speed = 0;
var instance = instance_place(x, y + 1, obj_Hplatform);//Returns ID
if(instance != noone) {
is_on_Hplatform = true;
     

if(input_horizontal == 0) // carry the player from left to right
       {
       horizontal_speed = instance.h_speed * instance.dir
       }}}
 
Last edited by a moderator:
N

nickvm98

Guest
Just add the speed of the platform directly to your player coordinates and make the platform the child object of a wall object parent. Don't repeat your vertical collision code twice.
 
Top