GMS: How to Move on Steps & Slopes? (Over View)
GMS File: https://bit.ly/3dQQwS3
Note: Not shown on video, be sure collision mask for player is a "Ellipse" NOT a Rectangle or Precise. This is due to moving up the Steps and Slopes.
Note: Be sure to parent obj_player_left with obj_player_right.
obj_player_right
Events:
Create
Actions:
///movement variables
m_speed = 10;
m_step = 5;
vspeed = 0;
m_gravity = 1 ///Jump in air
m_jump = -15;
Events:
End Step
Actions:
////movements
vspeed += m_gravity; ///allows to jump in air moving right or left
if keyboard_check(vk_left)
{
move_contact_solid(90, m_step);
move_contact_solid(180, m_step);
move_contact_solid(270, m_step);
}
if keyboard_check(vk_right)
{
move_contact_solid(90, m_step);
move_contact_solid(0, m_step);
move_contact_solid(270, m_step);
}
if keyboard_check_pressed(vk_up) ///jump in air moving right or left
if !place_free(x,y+1)
{
vspeed = m_jump;
}
Events:
Collision with obj_block, check solid ///Check solid for slopes too.
Actions:
vspeed = 0;
Events:
Collision with obj_right_slope
Actions:
vspeed = 0;
move_contact_solid(270,20);
Events:
Collision with obj_left_slope
Actions:
vspeed = 0;
move_contact_solid(270,20);