TouchInput in Update. Physics in FixedUpdate. Lag and Lost calls?
So I know that FixedUpdate() should be used for Physics and ever since I read that I've been writing my Jumps, Movements etc. in FixedUpdate(). But now as I completed a touch input script in Update(), I find a severe lag between the Input checks made in Update() and the resulting Physics calculations in FixedUpdate(). For example, I made some prints inside the calls and got this:
"Swipe at 5.344789" "Movement at 5.36" "Swipe at 7.440634" (Missing movement call here) "Swipe at 8.274659"
Not only was the Movement Physics 0.02s late, the next Movement was lost entirely. This would happen on occasion, with various lag in between. Well, I moved all the movement scripts to Update(), exactly after the Touch Inputs, and everything worked instantly, although I had to put some Time.deltaTime multipliers to the Physics to make them smooth.
Why is this? Am I doing something wrong in gathering touch inputs and changing boolean states in FixedUpdate upon those inputs? What I've usually seen other people do is exactly that, like:
bool jump;
void Update() {
if (Input.touchCount > 0) {
// do necessary touch things
jump = true;
}
}
void FixedUpdate() {
if (jump) {
// do Jump physics
jump = false;
}
}
Is this a bad approach, or is the problem somewhere else?
Your answer
Follow this Question
Related Questions
Touch Controls inaccurate after screen sleeping 0 Answers
How can convert keyboard controller to touchscreen(android .ios ...etc) 1 Answer
Rotate Player w/Touch Input Controls 0 Answers
WebGL and videoplayer set frame not working in Unity 2019.4.0f1 1 Answer
How can I change my player control method to use a touch screen ?? Pong-clone 2D 0 Answers