Skip to main content
3 of 3
formatting + language improvements
Kromster
  • 10.7k
  • 4
  • 54
  • 67

Adding a small slide when player releases left/right key

The aim is for the player object to slow down and stop instead of just stopping dead. The following codes works ok when the player is not jumping, but gets stuck in an object if the player is in the air when they do it.

Left key released event:

if hsp = 0 exit;

hspeed = -3;
friction = 0.20;

if obj_Player.hspeed = 0 
{
hspeed = 0;
}

Right key released event:

if hsp = 0 exit;

hspeed = +3;
friction = 0.20;

if obj_Player.hspeed = 0 
{
hspeed = 0;
}

Horizontal collision code for interest:

if (place_meeting(x+hsp,y,obj_bound))
{
while(!place_meeting(x+sign(hsp),y,obj_bound))
{
    x += sign(hsp);
}
hsp = 0;
}

x += hsp;
Dave
  • 41
  • 1