Game Development Reference
In-Depth Information
FixedUpdate()
The FixedUpdate() function is called every fixed framerate frame (or every constant
time), if the MonoBehaviour class is enabled.
Note
The difference between FixedUpdate() and Update() is that the Update() func-
tion is called every frame. On the other hand, FixedUpdate() is called every fixed
framerate frame. This depends on the Fixed Timestep value that we have set up. This will
result in stable physics calculations for all machines. For more information, visit the fol-
lowing link:
https://docs.unity3d.com/Documentation/Components/class-TimeManager.html
FixedUpdate() should be used instead of Update() when dealing with physics cal-
culations. For example, when adding a force to a rigidbody, you have to apply the force to
every fixed frame inside FixedUpdate() instead of every frame inside Update() , be-
cause the physics simulation is carried out in discrete timesteps. The FixedUpdate()
function is called immediately before each step. An example of FixedUpdate() is as
follows:
// JavaScript user:
// Apply an upward force to the rigidbody every frame
function FixedUpdate () {
rigidBody.AddForce(Vector3.up);
}
// C# user:
// Apply an upward force to the rigidbody every frame
void FixedUpdate () {
rigidBody.AddForce(Vector3.up);
}
Search WWH ::




Custom Search