Game Development Reference
In-Depth Information
Billboards and Bobbing
We're making good progress with the Cash Power-Up, but it still needs “something more” than just
the ability to act as a Billboard. To really “stand out” to the player as a collectible object, it needs to
move. True, the power-up technically moves already, as it always rotates to face the camera, but this
movement is practically imperceptible because it's perfectly synchronized with the camera. So to
create perceptible movement, we'll need to translate the power-up to move it. Specifically, we'll add
a bobbing motion, making the power-up gently move up and then down in a loop (see Figure 4-6 to
see the planned motion).
Figure 4-6. Adding bobbing motion to the power-up to help it stand out as a collectible object
The act of vacillating continuously between two extremes, such as moving up and down repeatedly,
is termed PingPonging . To create a PingPong for object movement, then, we'll need to create a
new C# class and component. I'll call this class PingPongDistance , since it'll move the power-up up
and down by a specified distance, back and forth. The development of this class will also introduce
two highly important concepts in Unity—namely, deltaTime and coroutines . Let's start the class, as
shown in Listing 4-5.
Listing 4-5. PingPongDistance.cs: Starting a PingPong Class for Animating Power-Up Movement
01 using UnityEngine;
02 using System.Collections;
03
04 public class PingPongDistance : MonoBehaviour
05 {
06 private Transform ThisTransform = null;
07
 
Search WWH ::




Custom Search