public void Movement(InputAction.CallbackContext context) {
inputVector = context.ReadValue<Vector2>();
Debug.Log(inputVector);
}
I use code above to recieve player’s input, but when I press and hold a certain botton like w, the debug log displays:
[15:24:00] (0.0, 1.0)
[15:24:00] (0.0, 0.0)
[15:24:00] (0.0, 1.0)
[15:24:00] (0.0, 1.0)
How do I filter the noise like this?
It’s going to print a lot with the log statement inside the event receiving script because of the way the devices fire off events with attached values, unless you write another script to handle it and then tell something else to update only when the value changes.
You might just want to try something like if(!context.performed) return; to only do something when it is the performed phase.
And the log goes:
[22:20:19] Started
[22:20:19] (0.0, 1.0)
[22:20:19] Canceled
[22:20:19] (0.0, 0.0)
[22:20:19] Started
[22:20:19] (0.0, 1.0)
[22:20:19] Performed
[22:20:19] (0.0, 1.0)
I use your code at the beginning of the method, and the rest code won’t be excuted unless the botton is hold about half second.But I guess I know what to do.
Again, thanks a lot.
It depends how you’re reading in the input. What update mode is it in? (Project Settings)
What binding type is it? Does it have any processors on it? To me that sounds like you put a hold processor on it. Even with the line I put in there you shouldn’t be waiting a half a second… It should be read within milliseconds either way. This is how I do it in my project and have no issues.