GameMaker: Studio

GameMaker: Studio

View Stats:
Character wont stop moving
I programmed my character to go left when the Keyboard Pressed left key event is called; and I programmed my character to go right when the Keyboard Pressed right key event is called.

However, when I let go of the left or the right key, my character will keep moving.
< >
Showing 1-9 of 9 comments
Daynar Jan 17, 2016 @ 7:43pm 
I assume you used the variable hspeed to do movement in which case add an event for the keyboard released left key and insert this bit of code
//check to see if the right key is being pressed before setting hspeed to 0 if keyboard_check(vk_right) hspeed = spd //spd = speed of left/right movement else hspeed = 0
and add this bit of code to the kayboard released right key event
//check to see if the left key is being pressed before setting hspeed to 0 if keyboard_check(vk_left) hspeed = -spd //spd = speed of left/right movement else hspeed = 0
Pie Eater 9000 Jan 17, 2016 @ 7:57pm 
Originally posted by Daynar:
I assume you used the variable hspeed to do movement in which case add an event for the keyboard released left key and insert this bit of code
//check to see if the right key is being pressed before setting hspeed to 0 if keyboard_check(vk_right) hspeed = spd //spd = speed of left/right movement else hspeed = 0
and add this bit of code to the kayboard released right key event
//check to see if the left key is being pressed before setting hspeed to 0 if keyboard_check(vk_left) hspeed = -spd //spd = speed of left/right movement else hspeed = 0
How do I do this within the GUI?
Pie Eater 9000 Jan 17, 2016 @ 8:01pm 
Also, why do the 'Keyboard' event and the 'Key Pressed' event seem to do the same thing?
FreshWaterFern Jan 17, 2016 @ 8:07pm 
Keyboard events are fired every step as long as the indicated key is being held down. Keyboard pressed is only fired once when the key is first pressed.
Pie Eater 9000 Jan 17, 2016 @ 8:42pm 
Originally posted by Seabass (The Human):
Keyboard events are fired every step as long as the indicated key is being held down. Keyboard pressed is only fired once when the key is first pressed.
Shouldn't my character stop moving if I let go of the specified button if I use the 'Keyboard Pressed' event then?
Sistermatic™ Jan 17, 2016 @ 9:03pm 
Originally posted by Smelly Pickles:
Shouldn't my character stop moving if I let go of the specified button if I use the 'Keyboard Pressed' event then?
Not if you don't explicitly stop the movement. Starting an action on a press doesn't neccessarily stop the action when you let go (depending on your logic).

Best way is to use the keyboard_release event if you won't code.
Last edited by Sistermatic™; Jan 17, 2016 @ 9:04pm
FreshWaterFern Jan 17, 2016 @ 9:45pm 
Originally posted by Sista:
Originally posted by Smelly Pickles:
Shouldn't my character stop moving if I let go of the specified button if I use the 'Keyboard Pressed' event then?
Not if you don't explicitly stop the movement. Starting an action on a press doesn't neccessarily stop the action when you let go (depending on your logic).

Best way is to use the keyboard_release event if you won't code.
Yep. Upon the key being released, set the hspeed or speed (whichever you are using) back to 0
Daynar Jan 17, 2016 @ 9:55pm 
You could change the origional event from pressed to the plain keyboard check, and add add hspeed = 0 to the keyboard released events. That way if you have two buttons pressed and stop pressing one it should still move in the correct direction, although movement may stop for a frame depending on when the events are triggered.
Pie Eater 9000 Jan 18, 2016 @ 6:51am 
Originally posted by Sista:
Originally posted by Smelly Pickles:
Shouldn't my character stop moving if I let go of the specified button if I use the 'Keyboard Pressed' event then?
Not if you don't explicitly stop the movement. Starting an action on a press doesn't neccessarily stop the action when you let go (depending on your logic).

Best way is to use the keyboard_release event if you won't code.
Ah, thanks!
< >
Showing 1-9 of 9 comments
Per page: 1530 50

Date Posted: Jan 17, 2016 @ 7:36pm
Posts: 9