Search code examples
c#iosunity-game-engineunityscript

Unity - Is this necessary to always apply force in fixed update


I'm using Unity to create my game for iOS devices, in which I have a dice (compressed cylinder shaped) object. I've created a custom function named "swipe", in which I determine the swipe direction by calculating from the start position and the end position.

I've applied force to this object. But when I run the function in the Update() call, it shows the debug messages but the physics doesn't work, but when I call the same function from FixedUpdate(), it works perfectly.

So, do I have to use the FixedUpdate() for all my physics calculations?


Solution

  • In a nutshell, it is to do with how each frame is handled and the difference between the rendering of frames and the speed it is done.

    From what I understand of it, if you start throwing your physics in your Update() it might not be executed every frame as its playing catch up, however by putting it in FixedUpdate() it can run. FixedUpdate() should be used when applying most physics-related functions, because you know it will be executed in sync with Unity Physics Engine.

    Where as in Update, it isn't fixed, it's based on the amount of frames being rendered and as such, it could be faster or slower in relation to how much work is going down through the rendering engine at any given time.

    So keep it simple, and separate away your Physics related code to a FixedUpdate. Ensures Synchronicity.

    If you don't quite understand it, or perhaps want a more indepth answer check out this one by the user Duck

    http://answers.unity3d.com/questions/10993/whats-the-difference-between-update-and-fixedupdat.html