Game Development Reference
In-Depth Information
Classified intel
Why do we need the LateUpdate() function instead of the Update() function in this
script? Well, we use it to guarantee that the player position is already updated when we are
performing the camera calculations. If we perform the calculation in the Update() func-
tion, the camera position might be calculated before the player position is updated. This
will result in jitter.
We can also explain it this way: we wait for the input from the user and then get the direc-
tion in which the character will move from the Update() function. Then, we use the pos-
ition of the character as the target position that our camera will follow and calculate the
camera position in the LateUpdate() function.
Note
What's the difference between Update() , LateUpdate() , and FixedUpdate()
functions? Update() is called for every frame. LateUpdate() is also called for every
frame but after all the Update() functions have been called. FixedUpdate() is called
for every fixed frame rate, which means that no matter how our game is running, slow or
fast, the FixedUpdate() function will always call at the same rate. For example, if our
game is slow, the FixedUpdate() function gets called more than once before calling the
Update() function.
The following link is useful for Update() and FixedUpdate() : ht-
tp://answers.unity3d.com/questions/10993/whats-the-difference-between-update-and-
fixedupdat.html .
This way, we will be able to track each movement of our character and the camera will fol-
low the direction smoothly without any jitter, as we can see in the following diagram:
Search WWH ::




Custom Search