Difference in behaviour for multiple movement keys held down

Bugs that are actually features.
steveyh25
Inserter
Inserter
Posts: 21
Joined: Fri Apr 16, 2021 6:50 pm
Contact:

Difference in behaviour for multiple movement keys held down

Post by steveyh25 »

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
User avatar
Klonan
Factorio Staff
Factorio Staff
Posts: 5290
Joined: Sun Jan 11, 2015 2:09 pm
Contact:

Re: Difference in behaviour for multiple movement keys held down

Post by Klonan »

That do be how the if-else statement is

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;
So not a bug
Maybe you have some feedback on what you would expect it to work like?
steveyh25
Inserter
Inserter
Posts: 21
Joined: Fri Apr 16, 2021 6:50 pm
Contact:

Re: Difference in behaviour for multiple movement keys held down

Post by steveyh25 »

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
Muche
Fast Inserter
Fast Inserter
Posts: 238
Joined: Fri Jun 02, 2017 6:20 pm
Contact:

Re: Difference in behaviour for multiple movement keys held down

Post by Muche »

What about

Code: Select all

if (moveRightActive && moveLeftActive) {
  moveRightActive = false; moveLeftActive = false;
}
if (moveUpActive && moveDownActive) {
  moveUpActive = false; moveDownActive = false;
}
...
i.e. stop moving?
Last edited by Muche on Sun Nov 24, 2024 1:23 pm, edited 1 time in total.
steveyh25
Inserter
Inserter
Posts: 21
Joined: Fri Apr 16, 2021 6:50 pm
Contact:

Re: Difference in behaviour for multiple movement keys held down

Post by steveyh25 »

I disagree with this as I actually like the "toggle movement" for evading spitters :D

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
Muche
Fast Inserter
Fast Inserter
Posts: 238
Joined: Fri Jun 02, 2017 6:20 pm
Contact:

Re: Difference in behaviour for multiple movement keys held down

Post by Muche »

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.
steveyh25
Inserter
Inserter
Posts: 21
Joined: Fri Apr 16, 2021 6:50 pm
Contact:

Re: Difference in behaviour for multiple movement keys held down

Post by steveyh25 »

I see what you mean. I fear logic like:

Code: Select all

if (wasMovingRightActive && moveLeftActive && moveRightActive)
    result = Direction::West
else if  (wasMovingLeftActive && moveLeftActive && moveRightActive)
    result = Direction::East
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
Post Reply

Return to “Not a bug”