Not sure if this is a bug / quirk or expected behaviour
If you hold down A and then repeatedly toggle D then your character will move from left to right
However if you hold down D and then repeatedly toggle A then your character will only move to the right
Same for W and S - your character will only "toggle move" if S was held down first
My keyboard is mechanical and has N key rollover, so I don't think this is a hardware issue
Linux build - version 2.0.21
Difference in behaviour for multiple movement keys held down
Re: Difference in behaviour for multiple movement keys held down
That do be how the if-else statement is
So not a bug
Maybe you have some feedback on what you would expect it to work like?
Code: Select all
Direction result = Direction::None;
if (moveRightActive && moveUpActive)
result = Direction::NorthEast;
else if (moveRightActive && moveDownActive)
result = Direction::SouthEast;
else if (moveLeftActive && moveDownActive)
result = Direction::SouthWest;
else if (moveLeftActive && moveUpActive)
result = Direction::NorthWest;
else if (moveUpActive)
result = Direction::North;
else if (moveRightActive)
result = Direction::East;
else if (moveDownActive)
result = Direction::South;
else if (moveLeftActive)
result = Direction::West;
Maybe you have some feedback on what you would expect it to work like?
Re: Difference in behaviour for multiple movement keys held down
hi,
Thanks for the reply. I am talking about opposite directions - if moveRightActive is true and you press the A key, then your character does NOT move left. However, if moveLeftActive is true and you press the D key, then your character DOES move right until you let go of the D key. (same issue in the north/south direction)
The point is that the behaviour is inconsistent as it depends on whether you were moving left or moving right first as to whether the new key will have an effect on movement or not. I would expect that the behaviour either ignores the new key OR it flips your running direction (regardless of which direction you started moving in). As it stands now it does both behaviours depending on whether you were moving left first, or right
Thanks for the reply. I am talking about opposite directions - if moveRightActive is true and you press the A key, then your character does NOT move left. However, if moveLeftActive is true and you press the D key, then your character DOES move right until you let go of the D key. (same issue in the north/south direction)
The point is that the behaviour is inconsistent as it depends on whether you were moving left or moving right first as to whether the new key will have an effect on movement or not. I would expect that the behaviour either ignores the new key OR it flips your running direction (regardless of which direction you started moving in). As it stands now it does both behaviours depending on whether you were moving left first, or right
Re: Difference in behaviour for multiple movement keys held down
What about
i.e. stop moving?
Code: Select all
if (moveRightActive && moveLeftActive) {
moveRightActive = false; moveLeftActive = false;
}
if (moveUpActive && moveDownActive) {
moveUpActive = false; moveDownActive = false;
}
...
Last edited by Muche on Sun Nov 24, 2024 1:23 pm, edited 1 time in total.
Re: Difference in behaviour for multiple movement keys held down
I disagree with this as I actually like the "toggle movement" for evading spitters
If anything I would suggest that the behaviour when holding down A first (and toggling D) is replicated, and the behaviour for holding down S first (and toggling W) is replicated
If anything I would suggest that the behaviour when holding down A first (and toggling D) is replicated, and the behaviour for holding down S first (and toggling W) is replicated
Re: Difference in behaviour for multiple movement keys held down
Based on the code above, it's not "toggling" the direction. It's giving priority to up and right.
It does not check the previous direction, just processes the currently pressed keys and outputs where the character should go now.
It does not check the previous direction, just processes the currently pressed keys and outputs where the character should go now.
Re: Difference in behaviour for multiple movement keys held down
I see what you mean. I fear logic like:
is starting to get overcomplicated as you also have to account for having W and S pressed as well
I'm not really sure what recommendation there is (if any). I just noticed that the behaviour was inconsistent
Code: Select all
if (wasMovingRightActive && moveLeftActive && moveRightActive)
result = Direction::West
else if (wasMovingLeftActive && moveLeftActive && moveRightActive)
result = Direction::East
I'm not really sure what recommendation there is (if any). I just noticed that the behaviour was inconsistent