- Home /
New Input System isn't letting me do diagonal movement with WASD/Arrow Keys.
I started switching my inputs to use the Input System. Everything seemed to be working well until I started switching the moving code. I'm using the "Move/WASD" action from the default player action map. My issue is that it doesn't seem to read diagonal movement. Left/Right doesn't mix with Up/Down on either WASD or the arrow keys. The Vector2 value I can read from the button press event never mixes them. If left and right are pressed at the same time, it triggers the cancel event. The same with up and down. But it never mixes Left/Right with Up/Down. If I press down, it will never trigger and event for left/right and if I hold down then hold left and then let go of down, it never triggers any other event until I let go of left to trigger the cancel event for the original down press event.
All I do at the event is grab the vector direction and hold it to update the position during Update().
public void Move(InputAction.CallbackContext context)
{
Debug.Log($"Started: {context.started} | Performed: {context.performed} | Canceled: {context.canceled} | MoveVec: {context.ReadValue<Vector2>()}");
_moveVector = context.ReadValue<Vector2>();
}
Is there something I'm not seeing. I've tried going through all of the Action Type and Control Types for Move action and all the Composite Types, Modes for the WASD composite. I can't seem to get it to read two different axis. Would I have to make different actions for Left/Right and Up/Down?
UPDATE
I went ahead and separated the Up/Down and the Left/Right keys into their own actions and it seems to be working this way. Not sure this is the intended interaction though.
public void Move_UpDown(InputAction.CallbackContext context)
{
Debug.Log($"UpDown | Started: {context.started} | Performed: {context.performed} | Canceled: {context.canceled} | MoveVec: {context.ReadValue<Vector2>()}");
_moveVector.y = context.ReadValue<Vector2>().y;
}
public void Move_LefRight(InputAction.CallbackContext context)
{
Debug.Log($"LeftRight | Started: {context.started} | Performed: {context.performed} | Canceled: {context.canceled} | MoveVec: {context.ReadValue<Vector2>()}");
_moveVector.x = context.ReadValue<Vector2>().x;
}
I have the same problem and I've discovered that it works fine with a hold interaction. But I really think that it is a dirty hack rather than a solution.
The way I dealt with hold is read to the move vector and move using _moveVector until the cancel event zero it. I'll have adjust this though if I have to different events for Left/Right and Up/Down and it seems to go against how they laid it out in the default action map.
Answer by radoslavchobanov · Dec 08, 2021 at 10:44 PM
Hello OP and other people that experience this kind of problem with diagonal movement. I had the exact problem where my input was either up/down or right/left (1, 0 or 0, 1) and did not have the diagonal input (0.7, 0.7). Make sure you select Action Type -> Value and Control Type -> Vector2, in the InputSystem Actions.
Isn't that how it's set as in the default "ExampleActions" player inputs? I think I originally copied it from there. I'll check it out again though, thanks for the update!
Your answer
Follow this Question
Related Questions
Help In Making a SphereCast for 3D Tire! Working RayCast Script included! 0 Answers
Input System Can't Catch Event on Update 0 Answers
How can I make GUI button send an input message when I press it? 0 Answers
Unity not detecting input device in build 0 Answers
I need to make the Camera Quit snapping to center... 1 Answer