Game Development Reference
In-Depth Information
PingPongDistance script onto the power-up object, adding it as a component. I've positioned the
Cash Power-Up in the scene, and set values for the properties for PingPongDistance in the Object
Inspector. You may need to play around with these values if your level or power-up object differs
from mine (see Figure 4-8 for the values I've used).
Figure 4-8. Adding a PingPongDistance component to the Cash Power-Up, making it bob up and down. Notice the MoveDir vector
specified as (0, 1, 0) for the power-up move direction
Power-Up Collision
Things are looking good for the Cash Power-Up created so far. It exhibits Billboard functionality
using the Billboard class, and also bobs gently up and down to accentuate its collectability, thanks
to the PingPongDistance class. But all of these behaviors are essentially cosmetic features, and
none of them actually make the power-up collectible. To truly round-off and complete the power-up
object, we'll want it to disappear from the level when collected by the player. And the player collects
the power-up simply by walking through it . That is, by colliding with it. Therefore, to implement
power-up collection behavior, we'll need to work with Physics Colliders, to detect when the Player
controller intersects the power-up bounding volume. So, before getting started at implementing this,
make sure Collider Visibility is enabled for the Scene viewport, allowing us to see colliders when we
create them. To do this, click the Gizmo button from the Scene toolbar and enable the BoxCollider
check box, if it's not enabled already (see Figure 4-9 to see how to do this).
 
Search WWH ::




Custom Search