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

Discussion in 'Tutorials' started by GilM, Jan 8, 2020.

  1. GilM

    GilM Member

    Joined:
    Jul 2, 2016
    Posts:
    17
    GM Version: 2.2.5.378
    Target Platform: Windows
    Download: N/A
    Links:
    [​IMG]


    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: Jan 10, 2020

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice