GMS 2 Gamemaker Studio 2: Moving Platforms and One Way Platforms(All in One)

GilM

Member
GM Version: 2.2.5.378
Target Platform: Windows
Download: N/A
Links:



Summary:

First of all, happy new year to everybody! Hope you're having a great one.
Just as the title mentions, this is an all in one tutorial video showing people how to handle jump through based static and moving platforms.

Tutorial:
The tutorial is in video format with timestamps. It showcases what you will be learning UPFRONT, so you don't have to waste your time scrolling through to see if this is something of interest to you.

Code:

player Script:

Code:
///@param object_name


with(argument0)
{
   if(other.vspd > 0)
   {
       if(place_meeting(x, y-other.vspd, other) && !place_meeting(x, y, other))
       {
           while(!place_meeting(x, y-1, other))
           {
               other.y += 1;
           }
           other.vspd = 0;
       }
   }
}

oJumpThrough Create Event:

_vspd = 0;
_hspd = 0;
_moveSpeed = 6;
_platDir = choose(-1, 1);


oJumpThrough End Step Event:


switch(object_index)
{
   case oHmovingPlatform:
 
   #region platform movement
       _hspd = _platDir * _moveSpeed;
       var wallCollision = place_meeting(x+_hspd, y, oSolid);
       if(wallCollision)
       {
           _platDir *= -1;
       }
   #endregion
 
   #region move the player along with the platform
   with(oPlayer)
   {
       //make sure there's no collision with the solid object
       if(!place_meeting(x+other._hspd, y, oSolid))
       {
           //make sure there's a platform 1 pixel below the player.
           if(place_meeting(x, y+1, other) && !place_meeting(x, y, other))
           {
               //move the player with the platform
               x+= other._hspd;
           }
       }
   }
   #endregion
       x += _hspd;
       //
   
       break;
   case oVmovingPlatform:
 
   #region platform movement
       _vspd = _platDir * _moveSpeed;
   
       var heightOffset = 80;
   
       var upAndDownWallCollisions = place_meeting(x, y+_vspd+(heightOffset*_platDir), oSolid);
   
       // is there a wall collision up or down?
       if(upAndDownWallCollisions)
       {
           //change the platform direction
           _platDir *= -1;
       }
   #endregion
   #region move the player along with the platform
   with(oPlayer)
   {
       //make sure there's no collision with the solid object
       if(!place_meeting(x, y+other._vspd, oSolid))
       {
           //make sure there's a platform 1 pixel below the player.
           if(place_meeting(x, y+abs(other._vspd), other) && !place_meeting(x, y, other))
           {
               //move the player with the platform
               y += other._vspd;
           }
       }
   }
 
   #endregion
       y += _vspd;
       //
       break;
   
}
 
Last edited by a moderator:
Top