24-Speed Powerup Animation and Behaviour Setup — Thought Process

The speed powerup shares a lot of similarities to the TripleShot powerup. Actually, regardless of what kind of powerup it is, it can be considered to be consisted of two parts:

  • The collectable
  • Effect on the player

In the previous (triple shot), the (tripleshot powerup collectable) is spawned at a time interval and interact with the Player, then enable the (tripleshot) function. By replacing the words in parenthesis with Speed powerup here, it means the effect we have to obtain is that:

  • the (speed powerup collectable) is spawned at a time interval and interact with the player, which then enable the (speed up) function.

Based on the description of this task, we can start implementing following the steps below:

  1. For the collectable

1.1 Create a prefab for the collectable, with a rigid body, a collider, a corresponding sprite, and animation
1.2 Behaviour script, that is, collide with the Player and call certain function in Player, very similar to the TripleShot powerup. Here we can introduce an ID system to label our powerups, such that when it’s tripleshot (e.g., ID=0), we call the tripleshot behavior in Player; when it’s speed (e.g., ID=1), we call the speed up behavior in Player, etc. Then we can switch between different IDs conveniently.

2. For the effect on the player
2.1 Similarly, we first need a bool to flag whether SpeedPowerup is active or not; then, we need a mechanism to speed up. Here we will introduce a multiplier of 2 to modify the speed when the corresponding powerup is active; we also need a power down routine to control the lasting time of the speed boost effect

2.2 Lastly, we just have to spawn the Speed powerup using the same spawn routine as the tripleshot powerup. As it would be too busy to spawn them at the same time — especially considering there will be more powerups coming up down the road — it would be more organic to spawn one type of powerup at time randomly.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store