Skip to content

Powerups

Bina Mircea edited this page Jan 14, 2023 · 4 revisions

Powerups

Powerups modify how the Player attacks. Some powerups can stack (EX: triple shot x 2 => 5 shots at once) and all powerups interact with each other (EX: you can have bouncing + homing + triple bullets)

Creating powerups

  • There are 2 types of powerups (created using scriptable objects): gun modifiers and bullet modifiers.
  • A new powerup can be created by making a script that inherits the powerup class and then creating a scriptable object for that script.
  • To create an item that gives the player a powerup we create a new game object and add the ApplyBulletModifier or the ApplyGunModifier, both of which require a powerup parameter.
  • ApplyBulletModifier calls the Apply method from the powerup and ApplyGunModifier adds the powerup to a list in GunFire then when we shoot a bullet we use the Apply method for every powerup in that list.

Gun Modifiers

Triple Shot

  • the gun fires 3 bullets in a cone at the same time instead of just 1
  • we increase the BulletsFired by 2
  • the bullets have a certain degree between them (BulletSpread), so they fire in a cone
  • when the gun fires we check how many bullets it has to fire, and when we instantiate a bullet we rotate then move it in that direction

Charged Shot

  • the gun can be charged by holding down the left mouse button. Upon releasing the button, the gun will fire a bigger bullet that does more damage depending on how long it was charged
  • the gun can still fire normal bullets by just clicking (or by not holding the button long enough) instead of holding the button
  • the gun has 3 charge levels and the initial, uncharged level (when the player releases the left mouse button without charging the gun at least once)
  • the gun gets a charge level every 0.75 seconds (shotCooldown in PlayerShooting.cs)
  • after charging the gun for at least 0.75 seconds, a charge bar will appear, indicating the current charge level
  • after releasing the button, the charge bar disappears, the bullet is fired and the charge level is reset

Repeating Shot

  • the gun can be charged by holding down the left mouse button. Upon releasing the button, the gun will fire multiple bullets in a line with a short delay between them (0.075 second). The number of additional bullets depend on how long the gun was charged
  • the gun can still fire normal bullets by just clicking (or by not holding the button long enough) instead of holding the button
  • the gun has 3 charge levels and the initial, uncharged level (when the player releases the left mouse button without charging the gun at least once)
  • the gun gets a charge level every 0.75 seconds (shotCooldown in PlayerShooting.cs)
  • after charging the gun for at least 0.75 seconds, a charge bar will appear, indicating the current charge level
  • after releasing the button, the charge bar disappears, the bullets are fired and the charge level is reset

Bullet Modifiers

Note! - the bullet should always move in the direction it is facing, so we freeze rigidbody rotation

Bouncy Shot

  • when a bullet hits a wall it should bounce off instead of being destroyed
  • the bullet bounces off walls a number of times (bouncesRemaining)
  • the bullet disappears after hitting an enemy or after hitting a wall after bouncesRemaining becomes 0
  • when the bullet hits a wall it rotates in the direction it is supposed to bounce and starts moving that way

Homing Shot

  • when a bullet gets close to an enemy it should start following it instead of going in a straight line
  • the bullet looks for the closest enemy every FixedUpdate
  • if the enemy is within a certain distance (homingDistance), the bullet unfreezes rigidbody rotation and starts rotating in the direction of the enemy with a certain speed (homingSpeed)

Clone this wiki locally