Projectile Data

v1.0

Each Projectile has a ProjectileData object attached to it. Many behaviors will make use of the Speed value on this object, to determine how fast the Projectile should move. The demo scene also utilizes the Damage value.

If you create your own Movement Behavior (or other Behaviors), you do not have to make use of the data in Projectile Data. However, I would advise that you do utilize it, and also customize your own class which inherits from it, allowing more custom funcationality specific to your game.

Most likely you will want to create a new class which inherits from ProjectileData, and has additional data you need for your projectiles.

Each game is unique. Projectile Factory comes with the extensibility required to let you build YOUR game.

This is the "Fast Projectile" in the demo scene, and some projectiles use this to move faster than others. The Damage value is used when a projectile collides with the Demo Target. Check the console, and the script, to see how.

Custom Class Example

The ProjectileDataDemoDamageOverTime inherits from ProjectileData, and is used for demo projectiles like lasers and flame throwers, which likely cause damage over time rather than per collision.

namespace MagicPigGames.Projectiles
{
    [CreateAssetMenu(fileName = "New Damage over Time Projectile Data", menuName = "Projectile System/Projectile Data - Demo Damage Over Time")]
    [System.Serializable]
    public class ProjectileDataDemoDamageOverTime : ProjectileData
    {
        protected override float CalculateDamage() => damage * Time.deltaTime;
    }
}

Here we update the CreateAssetMenu options, so that you can create new Scriptable Objects of this type, and override the CalculateDamage() method, multiplying it b y Time.deltaTime.

Your custom classes can go deeper, if you'd like, connecting your projectiles to your game data and stats, and even adding additional Properties that work with your custom Behaviors specific to your game.

Last updated