Creating a skill system where the skills behave differently depending on what upgrades you have

Hi!

After 2 days of both trial and error and looking around on google and keep hitting dead ends I decided to make a post.

What I am trying to achieve is the ability to create a skill system where I have a weapon that can be upgraded up to three times. These upgrades would be something like split shot where instead of firing one bullet the weapon fires three. This is pretty simple to do but when I combine it with other skills is where I can’t seem to get it to work. Say I have another upgrade that makes the weapon charge up to fire three consecutive bullets, I want this to combine with firing three bullets so it would be three waves of three bullets.

I have tried to use a polymorphism system where the different upgrades inheret from a base class. I have not tried to use ScriptableObjects but I believe this uses the same premise as polymorphism (feel free to correct me if I’m wrong).

Any ideas are welcome! I appreciate all help.

Feel free to ask any questions.

Polymorphism suggests you’re thinking inheritance. Instead, think composition. Your weapon will be composed of up to three upgrade components, plus another “upgrade” component that spawns a basic bullet.

Here’s a rough sketch of one way to implement this. Each component can specify a priority value and a Fire() method that returns a list of bullets. Use the priority value to order the components in a list. So if BasicBullet has priority 1, SplitShot has priority 2 and TripleShot has priority 3, the list order is: TripleShot → SplitShot → BasicBullet.

To fire:

  • The weapon starts at the beginning of the list, calling TripleShot.Fire().

  • This calls the next list element’s (SplitShot’s) Fire() method three times with a delay between each one.

  • SplitShot.Fire() calls the next list element’s (BasicBullet’s) Fire() method three times in a loop, offsetting each returned bullet by a small amount to scatter the shots.

  • BasicBullet.Fire() spawns a bullet.

Composition makes it easy to add new upgrades, too. Let’s say you want to make a flaming bullet. You could insert a FlamingBullet component in the list in this order: TripleShot → SplitShot → FlamingBullet → BasicBullet.

  • The weapon starts at the beginning of the list, calling TripleShot.Fire().

  • This calls the next list element’s (SplitShot’s) Fire() method three times with a delay between each one.

  • SplitShot.Fire() calls the next list element’s (FlamingBullet’s) Fire() method three times in a loop, offsetting each returned bullet by a small amount to scatter the shots.

  • FlamingBullet.Fire() calls the next list element’s (BasicBullet’s) Fire() method. Then it adds a flame particle system to each returned bullet.

  • BasicBullet.Fire() spawns a bullet.

Or you can double things up. Let’s say you upgrade a weapon with two SplitShots: SplitShot → SplitShot → BasicBullet.

  • The weapon starts at the beginning of the list, calling SplitShot.Fire().

  • SplitShot.Fire() calls the next list element’s (another SplitShot’s) Fire() method three times in a loop, offsetting each returned bullet by a small amount to scatter the shots.

  • The other SplitShot.Fire() calls the next list element’s (BasicBullet’s) Fire() method three times in a loop, offsetting each returned bullet by a small amount to scatter the shots.

  • BasicBullet.Fire() spawns a bullet.

This double-up of SplitShot will produce 3 x 3 = 9 bullets with each firing, without having to write any special cases to handle double-ups.

To implement this, you can make each upgrade a MonoBehaviour, and add them to your weapon GameObject to compose a set of upgrades.

5 Likes

That is a really interesting way to look at it.

Have not yet got it to work as I did not have that much time to work on my project today but I have made some progress in trying to implement this!

Thanks alot. Will ask if I run into any problems :slight_smile: