Game Development Reference
In-Depth Information
Save and play. Move the cube around with the arrow keys, then press O to return it to the center of
the Game View. Notice that this resets the cube's position without having any effect on its rotation.
While effectively instantaneous, this movement is rather abrupt. If you'd like a slower, smoother
return to origin for the cube, Unity has a great function just for this purpose called Lerp() .
Smoothing It Out with Lerp
Unity's Lerp() function can smooth the cube's transition back to the origin. Lerp stands for Linear
Interpolation, which is a mathematical way of approximating a smooth line or curve between two
values. In this case we are using Lerp() for smoothing the movement of the cube from the position
the player moved it to, back to the origin. If you take a moment to search “Lerp” in the Scripting
Reference, you'll find Lerp() can be used to transition between two values representing just about
anything including colors, materials, and quaternions (Figure 5-4 ).
Figure 5-4. Static functions using Lerp() in Unity
 
Search WWH ::




Custom Search