#Can someone tell me why my character glides to the right?

4 messages · Page 1 of 1 (latest)

exotic cypress
#

this is the movement code


left_key = keyboard_check(vk_left) or keyboard_check(ord("A"));
right_key = keyboard_check(vk_right) or keyboard_check(ord("D"));
jump_key = keyboard_check_pressed(vk_up) or keyboard_check_pressed(vk_space) or keyboard_check_pressed(ord("W"));

//Calculate Movement

if left_key
{
    hsp -= walksp
}
if right_key
{
    hsp += walksp
}
if (hsp >= 0) and place_meeting(x,y + 1,oBlock) hsp -= fric;
if (hsp <= 0) and place_meeting(x,y + 1,oBlock) hsp += fric;


hsp = clamp(-max_speed,max_speed,hsp)```
#

and here's all of the relevant variables

hsp = 0;
max_speed = 8;
fric = 0.15;
grv = 0.4;
walksp = 0.5;```
fathom nacelle
#

if hsp is, say, 0.05, your friction code will set hsp first to 0.05 - 0.15 = -0.1 and then to -0.1 + 0.15 = 0.05, so you'll end up with a positive speed. you can replace hsp -= fric; with hsp = max(hsp - fric, 0); and hsp += fric with hsp = min(hsp + fric, 0);

exotic cypress