Skip to main content
Bumped by Community user
Tweeted twitter.com/StackGameDev/status/757954649752305664
Bumped by Community user
Bumped by Community user
Bumped by Community user
formatting + language improvements
Source Link
Kromster
  • 10.7k
  • 4
  • 54
  • 67

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;

Any help would be much appreciated. Thanks.

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;

Any help would be much appreciated. Thanks.

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;

theThe 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 Keykey released event: if hsp = 0 exit;

if hsp = 0 exit;

hspeed = -3;
friction = 0.20;

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

Right key released event: if hsp = 0 exit;

if hsp = 0 exit;

hspeed = +3;
friction = 0.20;

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

and here's the horizontalHorizontal 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;

Any help would be much appreciated. Thanks.

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;
}

and here's the 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;

Any help would be much appreciated. Thanks.

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;

Any help would be much appreciated. Thanks.

Source Link
Dave
  • 41
  • 1

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;
}

and here's the 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;

Any help would be much appreciated. Thanks.