• 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!

the instance doesnt want to move the way I want it to

D

Dirokiwi

Guest
i am working on a 2d platform game, so the controls, have to be good. My idea is, that if the player is holding down right arrow key(walking right) and then starts holding down left arrow key, while still holding down the right arrow key, it will move in the left direction. Or if the player is holding down left arrow key(walking left) and then starts holding down right arrow key, while still holding down the left arrow key, it will move in the right direction.
Here is the code I written if the first situation i mentioned occured.


(step event)
if keyboard_check(vk_right)
{
x = x + 4
sprite_index = s_player_run;
image_xscale = 12;
if keyboard_check(vk_left)
{
x = x - 4;
sprite_index = s_player_run;
image_xscale = -12;
}
}


but if I use the same code(almost) for the second situation i mentioned, and the game would sense that i am pressing two keys at once, the player wont move. I recorded a clip, so you can understand better what I am talking about (if you want to have a look at it please on instagram search for dirokiwi123, and there you will see the clip) Please help my idea mentioned in the top of the description become reality.

I will be grateful for any kind of replies. Have a nice day.
 
Last edited by a moderator:

TheouAegis

Member
The funny part is you are trying to program around the shortcomings of a keyboard. You do realize by allowing the player to hold two direction keys at the same time, you are in essence encouraging the player to force keyboard ghosting which will potentially prevent the player from being able to attack or jump.

hmove = sign(keyboard_check(RIGHT) + keyboard_check_pressed(RIGHT)*2 - keyboard_check(LEFT) - keyboard_check_pressed(LEFT)*2 + sign(hmove));
x += 4*hmove;
if hmove!=0 sprite_index=s_player_run;
image_xscale=12*hmove;
 
D

Dirokiwi

Guest
The funny part is you are trying to program around the shortcomings of a keyboard. You do realize by allowing the player to hold two direction keys at the same time, you are in essence encouraging the player to force keyboard ghosting which will potentially prevent the player from being able to attack or jump.

hmove = sign(keyboard_check(RIGHT) + keyboard_check_pressed(RIGHT)*2 - keyboard_check(LEFT) - keyboard_check_pressed(LEFT)*2 + sign(hmove));
x += 4*hmove;
if hmove!=0 sprite_index=s_player_run;
image_xscale=12*hmove;

as you could see, i am a beginner, i do not understand your code, so I am asking you, in what event do I put It and exactly which part of my code it will replace?
Thank you for the reply.
 
Top