Adding a small slide when player releases left/right key
Posted
by
Dave
on Game Development
See other posts from Game Development
or by Dave
Published on 2014-06-07T01:48:02Z
Indexed on
2014/06/07
3:49 UTC
Read the original article
Hit count: 246
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.
© Game Development or respective owner