playMaker

Author Topic: [SOLVED] Logic for damage mechanics with multiple enemies and weapons  (Read 2233 times)

Fat Pug Studio

  • Beta Group
  • Hero Member
  • *
  • Posts: 1294
    • Fat Pug Studio
Hi guys,

i posted this on unity forums, but i would like to hear your opinion too!

I am implementing the normal/half/double damage mechanics. The way i do it is like this (simplified):

There are two types of weapons:

1. Bullet
2. Energy

Eash type of weapon can be upgraded, so we have something like this:

1. Bullet Level 1 (deals 2 damage)
2. Bullet Level 2 (deals 4 damage)
3. Energy Level 1 (deals 4 damage)
4. Energy Level 2 (deals 8 damage)

There are two types of enemies too:

1. Red enemy - Bullet does normal damage (2 and 4), Energy does half damage (2 and 4)
2. Blue enemy - Bullet does normal damage (2 and 4), Energy does double damage (8 and 16)

Now, when the bullet enters the collider, it is registered by tag (Bullet Level 1, Bullet Level 2, Energy Level 1, Energy Level 2), corresponding to that, damage variable is called and, depending on the enemy type, it is multiplied, divided, or left as it is. This is a fairly simple example, and the total number of combinations is 8. However, when we insert 20 weapons with 4 upgrade levels and 40 types of enemies, things start to look like spaghetti, overly complicated and hard to maintain.

If there would be a possibility to multiple tag the object and to particular number of damage point when a set of tags is recognized it would be much easier, alas, it is not supported (yeah, i know about the stuff on the asset store, but i want to see what other legit way to do this would be. Besides, i think those are useful only for organizing, i wouldn't know how would i compare multiple tags).

The FSM is:

First state:

Collision 2D event/Compare Tag

Second state:

Int Operator with divide or multiply operator depending on type of damage, or only take damage if there are no modifications.

I would like to hear your opinion :)
« Last Edit: September 16, 2016, 01:32:51 PM by krmko »
Available for Playmaker work

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Hi,

Quote
If there would be a possibility to multiple tag the object and to particular number of damage point when a set of tags is recognized it would be much easier, alas, it is not supported (yeah, i know about the stuff on the asset store, but i want to see what other legit way to do this would be. Besides, i think those are useful only for organizing, i wouldn't know how would i compare multiple tags).
Maybe you can set layers and
use get layer and do an int switch

Fat Pug Studio

  • Beta Group
  • Hero Member
  • *
  • Posts: 1294
    • Fat Pug Studio
The guys on Unity forums recommend using Enums, as i feared, since it's a bittle unknown to me. But it had to be learned someday. Here's the topic if anyone is interested, cool stuff.

http://forum.unity3d.com/threads/logic-for-normal-half-double-damage-mechanics-with-multiple-enemy-types-and-weapons.428189/
Available for Playmaker work

Fat Pug Studio

  • Beta Group
  • Hero Member
  • *
  • Posts: 1294
    • Fat Pug Studio
Believe it or not, add multiple tag action somehow bypasses the unity's one tag per object restriction, so there's no need for headbanging, i can easily apply multiple tags to any object. Another victory for playmaker!

Edit: Actually, it's not quite as i have imagined, multitag sets only the last tag :P

Anyway, i figured it out the other way, every object spawns an empty child object with a tag when it instantiates.
« Last Edit: September 22, 2016, 07:45:43 AM by krmko »
Available for Playmaker work