• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Player Horizontal Movement Problems

J

Jaften

Guest
Hello people,

In need of some advice here. Before we start know that I am very raw and still learning GMS, I am mostly a drag and drop guy (dont really have time in my life to learn even GML).

After some testing, my player movement (left and right) kept stopping mid movement. I figured out that it is the release key command that is doing this. After I have changed direction if I am still holding down the last direction key and then release it, it stops all movement thus making the player object stop completely.

Here is what I am looking for:

press right, object moves right
release right, object stops (vice versa for left)

press right, object moves right, press left (still naturally holding right key) object moves left,
(naturally) release right and object continues to move left
release left, object stops (and vice versa)


Would prefer a DnD solution but willing to try anything.

Thank you in advance

J
 
Last edited by a moderator:
L

Leonidus1989

Guest
The quick and dirty way of doing this with drag n drop, set the direction key release as well.
So if you have key_press <left>, then also have key_release <left> as well. press left will have the movement math in the actions (move fixed in move tab), and release will have movement with the center selected and value set to 0.

The other option is code based. For movement, this is pretty straight forward and quick.
In the object create a "create" event. drag the 'execute code' into actions. then enter "/// a" into there, green check mark.
Next, create the 'step' event. drag and drop the execute code again and just copy and paste this:


Code:
/// player movement
// 4 directional controls. Arrow keys
if (keyboard_check(vk_right)) { x+=4 }
if (keyboard_check(vk_left)) { x-=4 }
if (keyboard_check(vk_up)) { y-=4 }
if (keyboard_check(vk_down)) { y+=4 }
Hopefully this helps.
 
S

SyntheticStorm9

Guest
do this in step event
//player movement
hspeed = playerwalkingspd * (keyboard_check(ord('D')) - keyboard_check(ord('A')));
vspeed = playerwalkingspd * (keyboard_check(ord('S')) - keyboard_check(ord('W')));

do this in create event
//vars
playerwalkingspd = 3

Keep those reqests coming!
Psst.. it makes me look good in front of the other forumers...
 
Top