- Home /
Exactly when are inputs updated?
Let's say we get GetAxis and move player in Update function. What we would do is check input and than move some distance based on Time.deltaTime, so time between this update and last update, since we base on deltaTime to calculate distance travelled it should mean that input was received during last update right? I mean we just say that since user clicked "left" 0.2 seconds ago it means that player would travel 0.2 *speed. But as far as I see Inputs are triggered just before Update https://docs.unity3d.com/Manual/ExecutionOrder.html. Does this mean that actually we don't correctly calculate distance traveled? I understand that even if that's true we won't notice any difference.
Answer by NorthStar79 · Dec 06, 2017 at 08:06 AM
Inputs get updated right before Update() usually this does not cause any reasonable time shift but yes there will be an input lag between real key press time and Update() method. This does not mean that you are calculating distance travelled false, just means you can not react input changes very precisely. but as you said too, this won't create any change unless you are using Unity to simulating an interstellar probe's trajectory which is moving at relativistic speeds :)
Not only lag between real key press time and update. Let's say let's say we click "left" exactly at the time inputs are calculated and now in Update we see that user clicked "left" button, time between input check and update is e.g 0.001 and deltatime is 0.2, so player should have traveled just 0.001 times speed but now we would make it travel 0.2 times speed right? Just trying to understand it well :)
yeap that's the exact situation would have occurred in that scenario. and you can decrease its Error by using something like this:
if(Input.Get$$anonymous$$ouseButtonDown(0) == false && Input.Get$$anonymous$$ouseButton(0))
this will increase the Input lag but also helps correctly calculate distance traveled.
Your answer
Follow this Question
Related Questions
Update() in non-component script? 3 Answers
Supplying Input from Update To FixedUpdate 1 Answer
Is there a way to modify Input Manager so that an ax is be able simulate an input from code? 0 Answers
how to make a configurable input 1 Answer
InputManager doesn't detect gamepad numbers correctly 1 Answer