- Home /
Input System Vector2 composite does not cancel?
Trying hard to invest in figuring out how to make this input system work but it is definitely confusing..
Short version of question: why is my bool isMoving never set to false after I release the key?
private InputControls inputCtrls;
private bool isMoving = false;
private Vector2 moveDirection;
private void Awake()
{
inputCtrls = new InputControls();
moveDirection = new Vector2(0,0);
}
private void OnEnable()
{
inputCtrls.Player.Enable();
inputCtrls.Player.Movement.started += Movement_started;
inputCtrls.Player.Movement.performed += Movement_performed;
inputCtrls.Player.Movement.canceled += Movement_canceled;
Debug.Log("Movements assigned");
}
private void Movement_started(InputAction.CallbackContext obj)
{
moveDirection = obj.ReadValue<Vector2>();
Debug.Log("Movement started: " + moveDirection.ToString());
isMoving = true;
}
private void Movement_performed(InputAction.CallbackContext obj)
{
moveDirection = obj.ReadValue<Vector2>();
Debug.Log("Movement performed: " + moveDirection.ToString());
isMoving = true;
}
private void Movement_canceled(InputAction.CallbackContext obj)
{
moveDirection = Vector2.zero;
Debug.LogError("Movement stopped");
isMoving = false;
}
private void OnDisable()
{
inputCtrls.Player.Movement.started -= Movement_started;
inputCtrls.Player.Movement.performed -= Movement_performed;
inputCtrls.Player.Movement.canceled -= Movement_canceled;
inputCtrls.Player.Disable();
}
void Update()
{
if (isMoving)
{
Debug.Log("Why does this message keep looping?");
}
}
Long Version of Question: I am trying to get a correct hold down behavior for a binding to a Vector2 composite (using WASD keys) for player movement. When this script is attached to my game object, the "~looping" message just continues to display even after I let go of the keyboard. In addition, "Movement Started" never displays. I would want it to display "Movement Stopped" after button release but that does not work with this as well. Could someone explain how this behavior does not seem to work for Vector2 bindings but it does work fine if the Action type is assigned to Button? I need to be able to use Vector2 composite for proper movement. Is there a reason the Vector2 composite does not behave the way a Button does?
Your answer
![](https://koobas.hobune.stream/wayback/20220613010726im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Help In Making a SphereCast for 3D Tire! Working RayCast Script included! 0 Answers
Is it good to specify what Actions of the Input Manager do on several Scripts? 1 Answer
Accelerometer calibration works on Unity Remote, but not on device after build.. 1 Answer