• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Problem with moving platforms

S

Samuel Alles Remlinger

Guest
Hi guys, how are you? im having trouble with moving platforms, i tried a bunch of stuff to fix the problem, but nothing works. So i have 3 objects for platforms: platform_hor (moves horizontally);platform_up (moves up). and platform_down (moves down). When platform_down gets to the bottom of the room, it transforms its vspeed into -vspeed and transforms to platform_up. Same ideia for platform_up. Im having the following problems: When the player touches platform_hor, the platform stops moving. The player gets stuck on platform_down, and platform_up. On collision event with any of the moving platforms i put gravity = 270,0 and Move to contact in direction: 270,-1,solid objects; (those are drag and drop actions, not code). On step event i put the following codes:
Code:
///Horizontal Platform
if position_meeting(x,y+109,obj_platform_hor)
  {
  objID=instance_position(x,y+109,obj_platform_hor)
  hspeed = objID.hspeed;
  jump = false;
  run = false;
  if hspeed > 6
     {
        hspeed = 6;
     }
  if hspeed < -6
     {
        hspeed = -6;
     }
  if keyboard_check(ord("K")) then
    {
    jump = true;
    if (sound_isplaying(sou_jump) = false)
    {
       audio_play_sound(sou_jump,1,false);
    }
    vspeed = -25;
    }
  }
///Platform Up
if position_meeting(x,y+109,obj_platform_up)
  {
  objID = instance_position(x,y+109,obj_platform_up)
  vspeed = objID.vspeed;
  jump = false;
  move_outside_solid(90,sprite_height);
  if keyboard_check(ord("K")) then
    {
    jump = true;
    if (sound_isplaying(sou_jump) = false)
    {
       audio_play_sound(sou_jump,1,false);
    }
    vspeed = -25;
    }
  }
///Platform Down
if position_meeting(x,y+109,obj_platform_down)
  {
  objID = instance_position(x,y+109,obj_platform_down)
  vspeed = objID.vspeed;
  jump = false;
  move_outside_solid(90,sprite_height);
  if keyboard_check(ord("K")) then
    {
    jump = true;
    if (sound_isplaying(sou_jump) = false)
    {
       audio_play_sound(sou_jump,1,false);
    }
    vspeed =-25;
    }
  }
///Check if there is a platform up or down under it
onplatform = false;
if (self.y > 0)
{
if (instance_number(obj_platform_up) > 0)
{
nearest_up = instance_nearest(self.x,self.y,obj_platform_up);
if ((place_meeting(self.x,self.y+self.vspeed+nearest_up.vspeed,nearest_up) || (self.y+109+self.vspeed <= nearest_up.y+nearest_up.vspeed && self.x > nearest_up.x -1 && self.x < nearest_up.x + 256 +1)) && self.vspeed > nearest_up.vspeed)
{
    jump = false;
    onplatform = true;
    dist = nearest_up.y - self.y + 109;
    if (dist + nearest_up.vspeed <= self.vspeed)
    {
        if (dist + nearest_up.vspeed > -25)
        {
            self.vspeed = dist + nearest_up.vspeed;
        }
        else
        {
            self.vspeed = -25;
        }
    }
    move_outside_solid(90,sprite_height);
}}

if (instance_number(obj_platform_down) > 0)
{
nearest_down = instance_nearest(self.x,self.y,obj_platform_down);
if (place_meeting(self.x,self.y+self.vspeed+nearest_down.vspeed,nearest_down) || (self.y+109+self.vspeed <= nearest_down.y+nearest_down.vspeed && self.x > nearest_down.x -1 && self.x < nearest_down.x + 256 +1))
{
    jump = false;
    onplatform = true;
    dist = nearest_down.y - self.y + 109;
    if (dist + nearest_down.vspeed <= self.vspeed)
    {
        if (dist + nearest_up.vspeed < 30)
        {
            self.vspeed = dist + nearest_up.vspeed;
        }
        else
        {
            self.vspeed = 30;
        }
    }
    move_outside_solid(90,sprite_height);
}}}
the variable onplatform is used to deactivate the gravity. And i used y + 109, because the distance from the origin of the player sprite to the bottom of the player mask (i used a different sprite for mask) is 109. Also, the platform objects are solid, and i apllied shaun spalding's one way platform tutorial to them, it turn their sprite_index into -1, when the player is not above them. Please, someone help me, im stuck on this for months. What im i doing wrong?
 
Top