I have a vehicle that can be moved by either the WASD keys, the arrow keys, or the left joystick on a gamepad, all of which are mapped to an action called Move
in the new input system. I want to give the player the ability to switch between using keyboard and gamepad input during gameplay.
My vehicle movement script works as follows. In LateUpdate
, I execute Turn(controls.Game.Move.ReadValue<Vector2>().x);
and Drive(controls.Game.Move.ReadValue<Vector2>().y);
.
Here is the Turn
function:
void Turn(float direction)
{
if (direction != 0)
{
rb.angularVelocity = turningSpeed * -direction;
}
}
Here is the Drive
function:
void Drive(float direction)
{
if (direction != 0)
{
rb.velocity = transform.up * movementSpeed * direction;
}
}
When I press play, the left joystick works perfectly. However, the WASD keys, arrow keys, and left joystick on the gamepad seem to interfere with each other. For example, if I move the vehicle with the joystick, then use the WASD keys, the joystick input stops working. Any ideas on fixing this? I’m really confused.
I’m using Unity 2019.2.0f1 with Input System 0.9.0 and a Xbox One controller.
Thanks in advance!