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

Legacy GM Problem with diagonal movement

N

niko_argento

Guest
Hi,in my top down game i created some special movement where the player moves fast from a point to another point,like Flash,for this i use Space key,but one combination doesn´t work at all and the player does not move,these are the main codes in my object player:

Code:
CREATE EVENT

//initialize variables
image_index=0;
image_speed=0;
global.walkingspeed=3;

STEP EVENT

//aiming and direction

image_angle=direction;
direction=point_direction(x,y,mouse_x,mouse_y);

//movement and animation

if keyboard_check(ord("W")) {y-=global.walkingspeed; image_speed=0.2;}

if keyboard_check(ord("S")) {y+=global.walkingspeed; image_speed=0.2;}

if keyboard_check(ord("A")) {x-=global.walkingspeed; image_speed=0.2;}

if keyboard_check(ord("D")) {x+=global.walkingspeed; image_speed=0.2;}

//stop moving and stop animation
if keyboard_check_released(ord("W")) {y-=0;image_speed=0; image_index=0;}

if keyboard_check_released(ord("S")) {y+=0;image_speed=0; image_index=0;}

if keyboard_check_released(ord("A")) {x-=0;image_speed=0; image_index=0;}

if keyboard_check_released(ord("D")) {x+=0;image_speed=0; image_index=0;}

KEY PRESS EVENT:SPACE

if global.walkingspeed > 1
{
global.walkingspeed=15;
alarm[0]=10;
}

//diagonal move

   if (keyboard_check(ord("D")) && keyboard_check(ord("W")))  direction=45;

   else if (keyboard_check(ord("A")) && keyboard_check(ord("W")))  direction=135;

   else if (keyboard_check(ord("A")) && keyboard_check(ord("S")))  direction=225;

   else if (keyboard_check(ord("S")) && keyboard_check(ord("D")))  direction=315;


ALARM 0 EVENT

global.walkingspeed=3;
image_speed=0;
image_index=0;
The problem is when i press A+W,the player does not move,the other combinations work perfect,what is my mistake here?
 

Bingdom

Googledom
It likely due to your keyboard.

Create a new object, put this in the step event
Code:
x+= keyboard_check(vk_right) - keyboard_check(vk_left);
y+= keyboard_check(vk_down) - keyboard_check(vk_up);
Try to do that key combination again. If the error persists, it's your keyboard. ;)
 
J

JarodTheGreat

Guest
I tested your code, I seem to not have the issue which you're having problems with. Like Bingdom mention, the issue is probably your keyboard.
 
N

niko_argento

Guest
It likely due to your keyboard.

Create a new object, put this in the step event
Code:
x+= keyboard_check(vk_right) - keyboard_check(vk_left);
y+= keyboard_check(vk_down) - keyboard_check(vk_up);
Try to do that key combination again. If the error persists, it's your keyboard. ;)
hi,thanks for replying,i missed something,if i move the player normally,the combination A+W works,but in that event,space key event,the same combination does not work.
PD:your key combination works but also mine,the problem is when i add the space bar to that combination
 

Weird Dragon

Wizard
GMC Elder
Your code works when you don't press the spacebar because that is only a 2-key combination.
As soon as you have 3 keys pressed there can sometimes be problems on some keyboards with some of the combinations. It is called ghosting.

I have encountered this problem with the combination left arrow - up arrow - spacebar. If I then used the arrow keys on the numpad it worked fine.

Expensive gaming keyboards usually have something called "anti-ghosting". You can google the matter.
 
J

JarodTheGreat

Guest
hi,thanks for replying,i missed something,if i move the player normally,the combination A+W works,but in that event,space key event,the same combination does not work.
PD:your key combination works but also mine,the problem is when i add the space bar to that combination
Yes, even with the space bar I can work all combinations.
 
N

niko_argento

Guest
Your code works when you don't press the spacebar because that is only a 2-key combination.
As soon as you have 3 keys pressed there can sometimes be problems on some keyboards with some of the combinations. It is called ghosting.

I have encountered this problem with the combination left arrow - up arrow - spacebar. If I then used the arrow keys on the numpad it worked fine.

Expensive gaming keyboards usually have something called "anti-ghosting". You can google the matter.
hey i didn´t know about this,thanks for the info,so,the only solution for this is buy a new keyboard? or change the commands in my game i guess :(
 

Weird Dragon

Wizard
GMC Elder
hey i didn´t know about this,thanks for the info,so,the only solution for this is buy a new keyboard? or change the commands in my game i guess :(
You won't know how other people's keyboard is, so changing the code doesn't help, but making an alternative solution could be an idea so that the user has a choise. It is annoying but not much else you can do as far as I can see.
 
J

JarodTheGreat

Guest
How about something like this

CREATE EVENT:

moveburst = false

SPACE EVENT:

if moveburst = false
{
moveburst = true
alarm[0] = 20
}

ALARM 0 EVENT:

moveburst = false

STEP EVENT:

if moveburst = true { global.walkingspeed = 15 }

if global.walkingspeed = 15
{
if (keyboard_check(ord("D")) && keyboard_check(ord("W"))) direction=45;
else if (keyboard_check(ord("A")) && keyboard_check(ord("W"))) direction=135;
else if (keyboard_check(ord("A")) && keyboard_check(ord("S"))) direction=225;
else if (keyboard_check(ord("S")) && keyboard_check(ord("D"))) direction=315;
}

I have to head to work now. How ever let me know if this worked, if it didn't. I have another option. Best of luck!
 
N

niko_argento

Guest
How about something like this

CREATE EVENT:

moveburst = false

SPACE EVENT:

if moveburst = false
{
moveburst = true
alarm[0] = 20
}

ALARM 0 EVENT:

moveburst = false

STEP EVENT:

if moveburst = true { global.walkingspeed = 15 }

if global.walkingspeed = 15
{
if (keyboard_check(ord("D")) && keyboard_check(ord("W"))) direction=45;
else if (keyboard_check(ord("A")) && keyboard_check(ord("W"))) direction=135;
else if (keyboard_check(ord("A")) && keyboard_check(ord("S"))) direction=225;
else if (keyboard_check(ord("S")) && keyboard_check(ord("D"))) direction=315;
}

I have to head to work now. How ever let me know if this worked, if it didn't. I have another option. Best of luck!
i will try this and then i tell you the results,thanks a lot
 
N

niko_argento

Guest
How about something like this

CREATE EVENT:

moveburst = false

SPACE EVENT:

if moveburst = false
{
moveburst = true
alarm[0] = 20
}

ALARM 0 EVENT:

moveburst = false

STEP EVENT:

if moveburst = true { global.walkingspeed = 15 }

if global.walkingspeed = 15
{
if (keyboard_check(ord("D")) && keyboard_check(ord("W"))) direction=45;
else if (keyboard_check(ord("A")) && keyboard_check(ord("W"))) direction=135;
else if (keyboard_check(ord("A")) && keyboard_check(ord("S"))) direction=225;
else if (keyboard_check(ord("S")) && keyboard_check(ord("D"))) direction=315;
}

I have to head to work now. How ever let me know if this worked, if it didn't. I have another option. Best of luck!
well buddy i tried your code,it works,buuut i got another problem,once the player makes the fast move then the primal speed never returned,so i added this in the alarm event:

global.walkingspeed=3;

and when i tried again,it doesn´t work,like before
 
J

JarodTheGreat

Guest
Forgot to add this to step event, put " if moveburst = false { global.walkingspeed = 3 } " hope this helps!

Update: Just got home and tested the finished code, everything works as should. If you want the .gmz I built, let me know.
 
Last edited by a moderator:
N

niko_argento

Guest
Forgot to add this to step event, put " if moveburst = false { global.walkingspeed = 3 } " hope this helps!

Update: Just got home and tested the finished code, everything works as should. If you want the .gmz I built, let me know.
i think i quit :( it doesn´t work putting if moveburst = false { global.walkingspeed = 3 },the A+W combination does not work,why just that one?
 

Bingdom

Googledom
As far as I am aware, there is nothing you can do about it (unless you get a better keyboard). It's the hardware. Google 'Keyboard Ghosting' and you find your answer. ;)
 
J

JarodTheGreat

Guest
i think i quit :( it doesn´t work putting if moveburst = false { global.walkingspeed = 3 },the A+W combination does not work,why just that one?
Are you still pressing space while holding A+W? If so that's not what is intended. Youre suppose to tap space, and then hold A+W. Its not working cause you're probably holding down Space along with A+W.
 
J

JarodTheGreat

Guest
It might be the way you're programming it into your game too. If need be I will give you the .gmz file I built. I tested it thoroughly, and everything on my end works perfectly.
 

Weird Dragon

Wizard
GMC Elder
@niko_argento, if your keyboard has ghosting issues with those 3 keys A+W+Space, then that issue will be there no matter what sequence you press or tap the keys. When all 3 keys are pressed or tapped at the same time you have the problem.

You can read this: How to tell if your keyboard configuration suffers from ghosting

Check out your keyboard on this page: Keyboard Ghosting Explained! where it says "Click To Use" on top of the page.

For your game I suggest that you keep your original code and then use key-mapping. Look in the manual: keyboard_set_map

***

@JarodTheGreat, it is great that you are doing a lot to help on this matter, but it really does seem to be a keyboard-ghosting problem that isn't easy to cope with.
 
Top