How to handle FixedUpdate() and Input
As far as I know, in Unity, physics related things should be done in FixedUpdate() method. And FixedUpdate() is called at fix timestamp and Update() is not. Let's asuume I have a gameobject with RigidBody2D component attached. User can move the object with left and right arrow. See the fllowing figure, user input happen at frame 2 and 3 and FixedUpdate() is not called. During frame 2 user pressed right arrow and say it move the object 1 unit and object is currently located at (0, 0). The object position should be now at (1, 0). But nothing happen because FixedUpdate() wasn't called. And again in frame 3 FixedUpdate() is not called and user press the left arrow. So, it move the object 1 unit left and now the position is (0, 0). When we reached frame 4 FixedUpdate() is called and if I put the input data in a variable at previous frame, frame 3, current object position will be (0, 0). So, in this scanerio our gameobject never reached the position (1, 0) but it's supposed to be. Probably it's not the only problem. There might exist many scenarios like called FixedUpdate() 2 times within one frame and called FixedUpdate() every 3 or 4 frames and so on. So, can I ignore such case because I think it's not too obivious to user. If I can't how can I hadle it? Do I need to queue all the input data and do all the movement when the FixedUpdate() is called?
Your answer
Follow this Question
Related Questions
Do something after the next physics step (not the frame) 0 Answers
Speed inconsistent even when using time.dT + Fixed Update 3 Answers
Does GraphicRaycaster.Raycast produce more reliable results in Update or FixedUpdate? 0 Answers
GetAxis being missed in FixedUpdate work around? 1 Answer
Addforce in fixedupate 0 Answers