Package is still Work In Progress. (Feel free to improve it and drop a PR)
LUNA is an Asset Package dedicated to creation of weapons. Primarly it was focused on medieval-style weapons like swords or arrows, however I decided to also consider magic and guns (because why not).
It also has a advantage of being able to differentiate attack types within a single weapon (eg. piercing and slashing attack for sword based on velocity - spike of sword does pierce while blade does slash). This can be a useful feature for immersive VR gaming where you can beat different types of armor using same weapon.
- Unity.Mathematics
- Unity.Burst
- Unity.Collections
- Unity.Jobs
This is a weapon that is placed in world. It can be for example a spike in a spike trap (that pit Indiana Jones never has fallen into).
This type represents a weapon that can be wielded by user. Weapon damage is computed dynamically based on current weapon swing energy. The weapon energy / speed factor is defined by below formula:
Speed Factor is equal to modulus of moving average of velocity across specified timespan (expected attack time)
In other words: the system is resistant to things like quick wrist attacks while wielding a greatsword - as you need to smash it for a good second to gain full power.
You can also implement custom weapon types using WeaponBase abstract class.
Also it is worth noting that damage for a dynamic weapon (for static weapon speed factor is always 1) can scale via different methods:
Damage will always be equal to base damage. Simple as that. (Sometimes may be useful)
Damage is equal to base damage multiplied by speed factor. Eg. if speed factor is 20 and base damage is 10 then result is 10*20 = 200 DMG.
Damage is equal to base damage multiplied by speed factor to nTh power. Eg if speed factor is 10 and base damage is 5 then result is 5*10^2 = 500 DMG.
Damage is scaled exponentially - base damage is brought to power of speed factor eg. base damage is 10 and speed factor is 5 then damage is 10e5 DMG. This is good for nuclear blast :D
System supports multiple damage types including melee (slashing, piercing...), magic (fire, ice...) or other (poison, silver...)
Hitbox can have vulnerability and resistance to specified damage which leads to damage being multiplied or divided by specified factor. Of course hitbox also supports multiple types of vulnerability scaling (if multiple vulnerabilities exist):
- None: mult = max(mult1, mult2, mult3, ...)
- Additive: mult = (mult1 + mult2 + mult3 + ...)
- Multiplicative: mult = (mult1 * mult2 * mult3 * ...)
- Exponential: mult = (mult1 ^ mult2 ^ mult3 ^ ...), computationally expensive
Also weapon has different attack vectors which can lead to different types of damage types - eg. spike of sword is a Piercing attack, however blade is slashing. Hitting enemy with flat side of sword can be impact attack. In most games this thing is ignored.
Damage type of attack is always a logic sum of vector damage types and weapon damage types - if you want to make a fire sword, then you assign vector damage types to melee subtypes (like mentioned above) and weapon damage type to fire. Simple as that.
Enemy will have hitboxes that can have damage dealt to. Hitbox itself also has damage multiplier (default: 1) to support things like headshots or weaken hits to arms / legs.
Hitbox is directly related to vulnerabilities.
Weapons can have different damage dealing subsystems eg. on collision or on trigger enter. Those subsystems are separate MonoBehaviours. You should have at least one on your weapon to work properly.
Types of damage systems:
- Collision
- Trigger (you can scale trigger to simulate explosion)
- Demo scene
Check GitHub issue tracker.