R
Rustyknight
Guest
As some of you may know, I am working on a commercial side-scroller game, and although I have plenty programming experience, I have some trouble on some presumably simple things, such as acceleration and deceleration for the player.
The problems: The deceleration integer never decreases below 3. The deceleration variable should increase, but after walking for a short period (.7 to 1 second), the player should ideally walk without deceleration.
How might I go about this? And how might I make the code more efficient?
The problems: The deceleration integer never decreases below 3. The deceleration variable should increase, but after walking for a short period (.7 to 1 second), the player should ideally walk without deceleration.
How might I go about this? And how might I make the code more efficient?
Code:
move = -keyboard_check(vk_left) + keyboard_check(vk_right);
collidewith = obj_ground;
hsp = spd * move;
acel = hsp / 5;
accel = clamp(acel, 0, 6);
decel = clamp(decel, 0, 4);
spd = clamp(spd, 3, 10);
if(decel = 4){
candecel = false;
decel--;
}
if(keyboard_check(vk_left) && decel < 4 && candecel != false){
candecel = true;
decel++;
}
if(keyboard_check(vk_nokey)){
candecel = true;
}
while(place_meeting(x,y+1,collidewith)){
vsp = 0;
}
show_debug_message("speed decelerating by" + string(decel));
y+=vsp;
x+=hsp;
Last edited by a moderator: