I am learning to use Game Maker, and I thought it would be a good project to make some basic plane movement script. I finished the part that would move the plane and then added the part that would make the plane glide slowly to a halt. The issue is that whenever I press the down arrow key, the plane will move, but it will glide to a halt moving up, not down. Here is the code. Note: plane_speed = 0, plane_acceleration = 0.1.
// Check keyboard input for up and down keys
keyboard_up = keyboard_check(vk_up);
keyboard_down = keyboard_check(vk_down);
// Adjust plane speed based on keyboard input and switch costumes
if keyboard_up == 1 {
plane_speed = plane_speed + plane_acceleration;
y -= plane_speed; // Move plane up (assuming y is decreasing moves up)
sprite_index = Sprite3; // Change sprite to Sprite3 when moving up
}
if keyboard_down == 1 {
plane_speed = plane_speed + plane_acceleration;
y += plane_speed; // Move plane down (assuming y is increasing moves down)
sprite_index = sPlane; // Change sprite to sPlane when moving down
}
if keyboard_down == 0 && keyboard_up == 0
if plane_speed != 0 {
if (plane_speed > 0) {
plane_speed = plane_speed - plane_acceleration;
y -= plane_speed;
}
if (plane_speed < 0) {
plane_speed = plane_speed + plane_acceleration;
y -= plane_speed;
}
}
I have tried to switch around some of the plus and minus signs, but it will just make everything worse. Is it possible that I should switch the order of my code, is it a bug, or is it something else?