B
Blaize
Guest
EDIT: I changed the title from 'Attacking while moving' to the new one since it didn't make sense to me after reading it back.
So, I've just started sorting my move and attacking into two states and for the most part, they work fine. Actually, I can attack up, down, left, right, up-right, and down-left (essentially when both x and y values are different).
The problem is when both x and y have the same value (up-left and down-right) when I press the attack key, my guy doesn't go into the attack state.
Here's my code:
What's going on?
So, I've just started sorting my move and attacking into two states and for the most part, they work fine. Actually, I can attack up, down, left, right, up-right, and down-left (essentially when both x and y values are different).
The problem is when both x and y have the same value (up-left and down-right) when I press the attack key, my guy doesn't go into the attack state.
Here's my code:
Code:
///StateMain()
GetInput();
var horiz = Right - Left;
var vert = Down - Up;
if (horiz > 0)
PlayerDir = 0; //determines which sprite to draw
else if (horiz < 0)
PlayerDir = 2;
if (vert > 0)
PlayerDir = 3;
else if (vert < 0)
PlayerDir = 1;
sprite_index = vCharacterIdle;
image_index = PlayerDir;
if (Attack_)
{
CurrentState = States.Attacking;
}
Last edited by a moderator: