-
Notifications
You must be signed in to change notification settings - Fork 4
Powerups
TroacaDenis edited this page Nov 8, 2022
·
4 revisions
- 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.
- 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
Note! - the bullet should always move in the direction it is facing, so we freeze rigidbody rotation
- 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
- 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)