- Home /
How do I check for input that is faster than 1 frame?
I am having the player jump on hitting the jump button and slow down on releasing the button. This works great, unless the button is pressed faster than a single frame, so the question is how to check if the button has been pressed and released in between two update calls.
I don't think what you're asking is possible, but I would recommend trying
if (Input.GetButton("Jump")) {..jump and set grounded false..}
else if (!grounded) {..slow..}
This still does not register button presses that are shorter than 1 frame, so even though I hit the jump button nothing happens.
Is the button not registered or maybe the slow down that hide the effect of the button ? $$anonymous$$aybe try If (input.GetButton("Jump")) Debug.Log("buttonjump"); to see if it register..
There must be something else going wrong here. Detecting jump in the Update function is standard. I'd make sure that it is indeed listening for the input every frame, that there is no conflicting code, and that frame rate is well above 30fps.
If that's good then perhaps enter a fast clicking competition!?
That is all working, framerate at 50 etc; but if i hit the jump button and release it both inbetween update calls it will not register at all. So I guess there is no way to check if input has happened since the last update, is there maybe a way to have something that checks considerably faster than update?
Answer by guavaman · Oct 07, 2014 at 04:10 AM
If I understand your issue correctly, the game is running at a low frame rate and you are unable to detect input when the button press duration is less than the current frame rate. The only real solution to this is to decouple the input from the graphics update. Unfortunately, this is not possible using Unity's input system. Unity updates input only in the Update loop, so even if you get input in the FixedUpdate loop, that input is really only updated once per Update, meaning the input data is not refreshed necessarily every FixedUpdate when the frame rate is low.
There is a way around this problem, but it requires you go outside Unity to a native library to get your input. My input system Rewired does exactly this on Windows, Windows Store, and OSX. (Other platforms are supported but do not allow for framerate-independent input yet.) It refreshes the input information in the FixedUpdate loop which will be updated at the rate specified by the fixed timestep in Time Manager in Unity. By default, this is 50 fps, but you can increase that update rate further. When you get input in FixedUpdate or by using event-based input, you can get input at a constant rate even when the graphics slow down.
At present, there is a limitation however, in that Rewired does not use the native libraries for keyboard or mouse input. This may change in the future, but for now only joysticks and Custom Controllers (used for on-screen touch controls and other such custom input sources) are updated in this framerate-independent fashion.
Answer by Polymorphik · Oct 07, 2014 at 03:58 AM
Not sure what you are trying do here but you can use FixedUpdate to check if you are jumping then use update to see if they released the button. I think thats the best you can do, but again not sure what you are doing...
I made some test at 6 fps ... i always have 1 button registered in the update and 8 in the fixed update.
How faster could you release this button ?? You might be so fast that even the keyboard and the computer could not see anything !!!
Your answer
Follow this Question
Related Questions
Activate an input to pickup or search objectes 1 Answer
New Input system holding down a button 2 Answers
How to have user input behave the same through variable framerates? 1 Answer
Button.onClick.AddListener 1 Answer
How do I pass an input in Update() to FixedUpdate() for Physics movement? 2 Answers