GML Cancel Diagonal Movement.

D

derp556

Guest
Hi! Just wondering if I could cancel diagonal movement for animation purposes through this code:
(obj_player, step1)
///Movement
if keyboard_check(ord("S"))
{
down = 1
y += 4
}
else
{
down = 0
}

if keyboard_check(ord("W"))
{
up = 1
y += -4
}
else
{
up = 0
}

if keyboard_check(ord("A"))
{
left = 1
x += -4
}
else
{
left = 0
}

if keyboard_check(ord("D"))
{
right = 1
x += 4
}
else
{
right = 0
}
 

Bearman_18

Member
That could work, however, I would put your keyboard checks into variables and subtract the left variable from right and up from down and put those in two other variables. then multiply those variables by speed and add them to x and y, respectively. this will make collisions infinitley easier.
 

Bearman_18

Member
as far as canceling animation, though, you already use the first four necessary variables, so I would just set the keyboard_check code to them first, and use the method I put above. The codes good though, and just as valid. it should work. just using the method I described might kill several birds with one stone.
 
Top