5.3 Enhanced Input: Make two opposing inputs cancel each other out when pressed

Here is my input mapping:


It’s pretty simple. Pressing “A” gives a value of 1.0, and “D” gives a value of -1.0.

However, when holding both at the same time, instead of canceling out, “D” takes priority (which makes sense, as it uses the “negate” modifier).

Is there a way to make these two inputs cancel out instead of one taking priority? I don’t want to use separate mappings for each movement key, as that kind of defeats the purpose of using enhanced inputs, especially considering the old input system could do this fine.

Yea, it’s pretty simple actually. I randomly came across it when I had the same issue as you.

You can just go to the “InputAction_MoveLeftRight” asset and go to “Accumulation Behaviour” under the “Action” header. From there, select “Cumulative” rather than “Take Highest Absolute Value.” This will mean that the input will be a sum of whatever is being pressed.

i.e. If I press A (= 1) and D (= -1), the sum would be 0 (-1 + 1 = 0).

2 Likes

What should I do when I want to have the opposite of this, so that when I press A, it takes priority over D, and when I press D it takes priority over A? In my current implementation, when holding A, pressing D takes priority over A, but when holding D, pressing A wont do anything.

I don’t know, sorry. You could try figuring out a formula for it, since it has to work with the input values being A=-1 and D=1. The reason why your current implementation sounds like it only works one way is because you probably have highest absolute value as your accumulation behaviour in your input action asset. What this means is that when both input values for A and D received by the input action asset, it will take the answer in absolute value (absolute values are always positive). So A=-1 and D=1 will always equal 1 as the absolute value, meaning one direction will always take higher priority over the other.