How to disable the Diagonal movement (keypress AW, AS, WD, SD) of the charater in Top down 2D game?

Hi Everyone,

I am new to unreal and coding stuff, so I really need help from the community.
I am working on a game project and I want my character to move only:
Left = A
Right = D
Up = W
Down = S

However, currently, my character is also picking:
Left+Up = A + W
Left+Down = A + S
Up+ Right = W + D
Down+ Right = S + D

These combinations of the keys are creating diagonal movement in the gameplay, which I don’t want.

I will be really grateful if someone sends me a demo blueprint screenshot of the nodes to achieve this process.

Thank you.

I guess the easiest way to achieve this will be to restrict reading movement keys when other movement key is pressed. Meaning that when if hold W - then A and D will not do anything. For this you’ll need to create two booleans - bMoveHorizontal and bMoveVertical. When you press W or D the bMoveVertical is set to true, when you press A or D then bMoveHorizontal is set to true. When there is no movement (axis value=0) then variable turns to false. After you press a key you make a check to see if you already have movement along other axis.


Thank you JJtyan, I will work on this and I will let you know how it goes.