Infinity PBR by Magic Pig Games
  • Infinity PBR Documentation
  • Game Modules 4
    • ➡️Quick Start
    • 📽️Video Tutorials
      • Quick Start: Creating Game Module Objects
      • Automating Start Actions on GameModulesActor
      • Inflicting Damage with Conditions
      • Updating UI (and more) with Blackboard Notes
      • Dynamic Menus with Item Objects and Dictionaries
      • Create Custom Quest Rewards
      • Save and Load Game Data
      • Stats: Deep Dive
      • Items: Deep Dive
      • Conditions: Deep Dive
      • First Person Movement
      • Tutorial: "Overheal" Effect with Condition & Stats
      • Tutorial: Create a Character & Actor Class Inheriting from GameModulesActor
    • 👀Game Modules Viewer
      • Viewer: Dictionaries
      • Viewer: Stat / GameStatList
      • Viewer: ItemObject / GameItemObjectList
      • Viewer: ItemAttribute / GameItemAttributeList
      • Viewer: Condition / GameConditionList
      • Viewer: Quest / GameQuestList
    • V4 Migration Tips
      • Introducing GameModulesActor
      • Interfaces
      • No More Tick*
      • Dictionaries
      • Repositories
      • Tips from Upgrading "Legend of the Stones"
    • Important Information
      • Game Modules Overview
      • Inherit from GameModulesActor
      • Things to not forget to do
      • Bugs, Backups, and Demos
      • FAQ / Tips & Tricks
      • Required Prefabs
      • Game Module Repository
      • Release Notes
    • Module Documentation
      • Game Modules Actor
      • Game Module "Lists"
        • Get() Methods
          • GameStatList Get() Methods
          • GameItemObjectList Get() Methods
          • GameItemAttribute Get() Methods
          • GameConditionList Get() Methods
          • GameQuestList Get() Methods
        • Contains() Methods
          • GameStatList Contains() Methods
          • GameItemObjectList Contains() Methods
          • GameItemAttributeList Contains() Methods
          • GameConditionList Contains() Methods
          • GameQuestList Contains() Methods
        • Count() Methods
          • GameStatList Count() Methods
          • GameItemObjectList Count() Methods
          • GameItemAttributeList Count() Methods
          • GameConditionList Count() Methods
          • GameQuestList Count() Methods
        • Remove() Methods
          • GameStatList Remove() Methods
          • GameItemObjectList Remove() Methods
          • GameItemAttributeList Remove() Methods
          • GameConditionList Remove() Methods
          • GameQuestList Remove() Methods
        • GameStatList
        • GameItemObjectList
        • GameItemAttributeList
        • GameQuestList
        • GameConditionList
      • Blackboard
        • Blackboard.cs
        • Blackboard Follower
        • Blackboard Note
        • Blackboard Event
        • Blackboard Values
        • Tips & Tricks
          • Use extension methods to check BlackboardNotes (or events)
      • Stats
        • IHaveStats
        • Stat.cs
        • GameStat.cs
        • GameStatList.cs
        • Mastery Levels
      • Loot
        • LootItems.cs
        • LootBox.cs
        • GameLootBox.cs
        • Generating & Handling Loot
        • Custom Loot Generation Algorithm
      • Items
        • ItemObject.cs
          • Manage Item Objects
          • Allowed Item Attributes
          • Starting Item Attributes
          • Item Attribute Variables
            • Variables Methods
        • GameItemObject.cs
        • GameItemObjectList.cs
        • ItemAttribute.cs
          • Manage Item Attributes
          • General Settings
          • Name Settings
          • Requisite Attributes
        • GameItemAttribute.cs
        • GameItemAttributeList.cs
        • Code Examples
      • Conditions
        • Condition.cs
          • Main Settings
          • Condition Time
          • Effects on Points
        • GameCondition.cs
        • GameConditionList.cs
        • Expiration Condition Handler
        • Code Examples
      • Quests
        • Quest
          • Main Settings
          • Quest Step Settings
        • Quest Steps
        • Quest Conditions
          • Create a Custom Quest Condition
            • Your Quest Condition
            • Your Quest Condition Editor
            • Your Quest Condition Drawer
          • Quest Condition Details
            • Blackboard Value Bool
            • Blackboard Value GameObject
            • Blackboard Value Number
            • Blackboard Value String
            • Final Stat Is
            • Game Condition List Contains
            • Game Item Object List Contains
            • Game Stat List Contains
          • Quest Condition Enums
        • Quest Rewards
          • Create a Custom Quest Reward
            • Your Quest Reward
            • Your Quest Reward Editor
            • Your Quest Reward Drawer
          • Quest Reward Details
            • Point Reward
            • Condition Reward
            • Quest Quest Reward
            • Item Object Reward
          • Custom Quest Reward Handler
        • GameQuest
        • GameQuestList
        • Quest Events
        • Demo Scene Quests
          • Push the Button
          • Add Money
          • Don't Get Poisoned
          • Rescue the Puppy
      • Voices
        • Voices
        • Voice.cs
        • Code Examples
      • Dictionaries
        • Dictionaries Setup
        • Dictionaries Methods
        • KeyValue Methods
        • Save and Load
        • Object Reference
      • Gametime & Timeboard
        • Timeboard
          • Timeboard Events
          • TimeboardFollower
        • Gametime
          • Pause Level
          • Time Options
          • Properties & Methods
        • TimeSpan
        • Code Examples
      • Property Code
      • Lookup Table
      • Save and Load
        • GameList & GameFile
        • Making objects saveable
        • Saving, and Loading
        • BlackboardEvents sent by Save and Load
    • Game Module "Systems"
      • Drag-and-Drop Inventory System
        • Scripts
          • PanelManager
          • OnScreenItem
          • Panel
          • BoxManager
        • Scene & Class Setup
        • Item / Object Setup
        • Item / Inventory Setup
        • Box Setup (Chests, Bags, Other Inventories)
        • Setup Your Scene
      • First Person Movement
      • Character Creation
    • Game Module Demo Projects
      • Party Based RPG
        • Title Scene
        • Character Creation Scene
        • World & Dungeon Scenes
    • Magic Time for Game Modules
  • ✨Northstar Tracking System
    • ✅Overview & Quickstart
      • ➡️Quick Start
      • 🫐Demo Scene
      • 🛠️Customizing & Overriding
        • Create a Custom Navigation Bar
        • Create a Custom Compass / Radar
        • Runtime Overrides
          • Screen & Edge Overlay
          • Navigation Bar
          • Compass / Radar
      • ☄️Tips & Code Examples
    • Northstar Documentation
      • Global Northstar Settings
      • Northstar Overlay Settings
      • Compass & Radar
        • Compass
        • Radar
      • Northstar Screen Overlay
        • Screen & Edge Overlay
        • Navigation Bar
      • Tracked Target Compass Radar
      • Tracked Target Overlay
        • Types
        • Override Values
      • Overlay Icon
      • Compass Icon
      • Distance Text
  • 🚀Projectile Factory
    • 👀Overview & Quickstart
      • ➡️Quick Start Guide
        • Create Your First Projectile
        • Add Projectile Factory & Create a Projectile Spawner
        • Use 3rd Party Integrations
        • Extending Projectile Factory
        • Making Lasers & Similar Attached Projectiles
      • 💡FAQs + Important Reminders
    • Game Modules 4 Integration
      • Projectiles with TimeMod
    • Magic Time for Projectile Factory
    • ✅3rd Party Particle Integrations [16]
      • ▶️Archanor VFX [5]
        • Sci-Fi Arsenal
        • Polygon Arsenal
        • Magic Arsenal
        • Retro Arsenal
        • Rainbow Magic
      • ▶️Gabriel Aguiar Prod [2]
        • Unique Projectiles Vol. 1
        • Unique Projectiles Vol. 2
      • ▶️HOVL Studio [4]
        • Toon Projectiles
        • Toon Projectiles 2
        • AAA Stylized Projectiles Vol. 1
        • AAA Projectiles Vol. 2
      • ▶️kripto289 [1]
        • Realistic Effects Pack 4
      • ▶️FORGE3D [1]
        • Sci-Fi Effects
      • ▶️Knife [1]
        • PRO Effects - Sci-Fi Shooter FX
      • ▶️Jean Moreno [1]
        • Cartoon FX Remastered
      • ▶️Synty Studios [1]
        • 🟡Synty Studios Particles
    • Projectile Factory Documentation
      • 🔫Projectile Spawner
        • Projectile Spawner Code
      • 🚀Projectile
        • Projectile Code
        • Projectile Data
      • ✨Spawn Behavior
        • Spawn Behavior Code
        • Spawn Behavior Modification
      • 🕊️Behaviors
        • Behavior Examples
      • ⚡Events
      • 👁️Observers, Global Observers, and Observer Objects
        • Toggle Objects At Events Observer Object
      • 👩‍💼Factory Manager
      • 🏹Trajectory
      • 🎱Object Pooling
      • 🤩Create Custom Behaviors
      • Spawn Point Manager
      • Helper Tools
        • Projectiles Quick Editor
        • Set Trail Auto Destroy to False
        • Set Layer of All Projectiles
        • Remove Colliders
      • Additional Scripts
        • Destroy or Pool Object
        • Project Force
        • Raycast Shooter + Handlers
        • Projectile Utilities
  • Additional Systems & Tools
    • 🎨Runtime Color Sampler
      • Quick Start
      • Demo Walkthrough
      • Runtime Color Sampler (Prefab & Class)
        • Sampler Sphere
        • Sampler Camera
      • Runtime Listener
      • Runtime Color Settings
      • Scripting
      • Additional Classes
    • 🙎‍♀️Portrait Avatars
      • Setup
        • Create a Portrait Avatar
        • Create a UI Portrait
      • Portrait Avatars
        • Scripting
      • Portrait3D
      • Portrait2D
      • Portrait UI
      • Avatar Camera
      • Important Considerations
    • 🎛️Audio Clip Combiner
    • 🌈Color Shifter
    • 🛠️Support Classes
      • Utilities.cs
      • InfinityExtensions.cs
  • ⌛Magic Time - Local Time Scale
    • Overview
    • ➡️Quick Start
    • 🛠️Integrations
    • 💡FAQ
    • Local Time Scale
      • Local Time Scale Scripting
    • Magic Time Manager
      • Magic Time Manager Scripting
    • Magic Time User
      • IHaveLocalTime
      • Magic Time User Scripting
      • Additional "Magic Time User" Components
    • Time Zone
  • Equipment Systems
    • Overview
    • Blend Shapes Manager
    • Blend Shapes Preset Manager
    • Prefab and Object Manager
      • Humanoid Demo & Setup
      • EquipmentObject.cs
      • Prefab Groups
      • Variables
      • Scripting Examples
    • Wardrobe Prefab Manager
  • 📽️General Tutorials
    • Quick 3rd Person Controller
  • ⚔️Legend of the Stones
    • Actors, Players, NPCs
    • Systems
      • Game State
  • External Links
  • Get them at the Asset Store
  • Connect on Discord
  • YouTube
  • Twitch
  • 🚧Work In Progress / Coming Soon
Powered by GitBook
On this page
  • 1. Create the spawner
  • 2. Add a Projectile Spawner Component & Set It Up
  • Select the Collision Mask Layers
  • Set the Target
  • Add Projectiles
  • Add a Spawn Point
  • Spawn Point Manager
  • Select a Trajectory
  • 3. Optional: Test It!
  • 4. Connect Events
  • Add a ProjectileDemoActor to the Spawner
  • Add a Projectile Event
  • Add an Observer
  • 5. Optional: Test It!
  • You're Done!

Was this helpful?

  1. 🚀Projectile Factory
  2. 👀Overview & Quickstart
  3. ➡️Quick Start Guide

Add Projectile Factory & Create a Projectile Spawner

v1.0

PreviousCreate Your First ProjectileNextUse 3rd Party Integrations

Last updated 1 year ago

Was this helpful?

In this guide, we'll set up Projectile Factory, create a spawning object ("Projectile Spawner"), and get it spawning projectiles with the click of a button. Adding the same features to your existing actors will be essentially the same process.

Already have a character or other spawner? Feel free to skip the primative creation, and use that!

1. Create the spawner

For this, I'm going to copy the Projectile Spawner from the demo scenes. This object includes a cube for the base, a sphere for the hortizontal rotator, and an object to shoot things out of, which will also be our tilting transform.

A Spawner will generally have a "rotating" transform for horizontal rotations, and a "tilting" transform for vertical rotations. If none are provided, the base Transform will be used. Some Spawn Behaviors may make use of these values, but not all do.

Our Example Spawner has only one script, to keep the spawn point pointing toward the mouse position.

2. Add a Projectile Spawner Component & Set It Up

Add the ProjectileSpawner to this object. You'll notices a couple of red warnings in the Inspector. We'll fix these as we set it up.

Select the Collision Mask Layers

Projectile Spawners determine the default Layers that any Projectile will collide with. Each Projectile can override this value, but will otherwise inherit it. For the demo, we set this to include Default and Actor layers.

Set the Target

This is optional, but in the demo scene we do have some targets available, so I'll populate this now. In your game, you'll need to have methods to set the target, which all depends on how your game works. The Projectile Spawner documentation has more details on the SetTarget() method.

Add Projectiles

We'll add the Projectile we just created as here as well. Each list can have any number of projectiles, but needs at least one set. They can also be set at runtime.

Add a Spawn Point

Each Projectile Spawner can have any number of Spawn Points. Each Spawn Point has a rotating and tilting transform. Some Spawn Beahviors may make use of these transforms.

Spawn Point Manager

This spawner only has one spawn point, so we don't need to provide a Spawn Point Manager. If we had more than one Spawn Point, a Spawn Point Manager will determine how the points are selected. You can create your own Spawn Point Manager class to customize this logic for your project, and the different spawners in it.

Select a Trajectory

Each Projectile Spawner can also have an optional pre-launch trajectory behavior. This will be used when the ShowTrajectory value is true, prior to launching a trajectory. Individual Projectiles can also have a trajectory that displays while they are live in the world -- these are added the same as other Behaviors.

We will select the Hit Preview Overlay behavior.

3. Optional: Test It!

To test this, we can replace the demo actor with our new Projectile Spawner in one of the demo scenes.

The Demo Controller object with the DemoController component already has the logic set up to spawn projectiles. Dig into that script to see how it's done.

4. Connect Events

To fully use the Projectile Factory, your classes will need to know when things happen. There are two kinds of Events on a Projectile Spawner -- Spawner Events and Projectile Events. The Spawner itself calls the Spawner events, and the Projectile events are passed to each Projectile it creates. Those projectiles call the Projectile events.

Add a ProjectileDemoActor to the Spawner

The ProjectileDemoActor is a very basic "Actor" class -- the targets are also Actors, in this case NPCs. These are the things that can give and take damage.

The details on the script don't really matter for this purpose. This section is intended to demonstrate how you can connect your classes to the projectile system, so that your players can cause damage, and take damage, from projectiles.

Add a Projectile Event

First, let's add a Projectile Event. On this tab, expose the On Launch event, and drag in the spawner object from the Hierarchy view. Then select the AddProjectileLaunched method.

The demo scene will display the number of projectiles launched in the UI. This is one way to ensure your classes know what's happening with Projectiles, by using UnityEvents.

Add an Observer

Another method to connect your classes with the Projectile Factory is through Observers. View the Setup area on the Projectile Spawner, and add the Demo Actor Observer to the list.

Observers inherit from Projectile Behavior, so have all the same life-cycle events that any other Behavior has. The Observer waits for OnCollision or OnTrigger, before acting.

public ProjectileDemoActor Actor { get; set;  }
        
// In this demo, we will register the owner of the projectile OnLaunch, so that when the projectile hits another
// actor, we can apply damage to that actor. And the other actor will know where the damage came from! Often
// damage will be based on the stats of the attacking actor, so it's important to know who the attacker is.
public override void LaunchProjectile(Projectile projectile)
{
    var actor = ProjectileOwner.GetComponent<ProjectileDemoActor>();
    if (actor == null)
    {
        Debug.LogError("Projectile owner does not have a ProjectileDemoActor component!");
        return;
    }
    Actor = actor;
}

//...
        
public override void CollisionEnter(Projectile projectile, Collision collision, GameObject objectHit = null, Vector3 contactPoint = default)
{
    if (Actor == null)
        return;
    
    HitObject(objectHit);
}

// This is where we ensure the object we hit was an actor, and then send the information to our actor, which
// will handle the logic of actually doing the damage. This just says "Hey, we hit another actor!"
protected virtual void HitObject(GameObject objectHit)
{
    var actorHit = objectHit.GetComponent<ProjectileDemoActor>();
    if (actorHit == null)
        return;

    Actor.RegisterHit(Projectile, actorHit); // Send the hit information to the actor
}

The HitObject method checks to see if the object has a ProjectileDemoActor on it. If it does, it calls the RegisterHit method on the Actor who spawned the projectile. This is how the player actor causes damage on the targets.

Your own classes can do whatever they want with the data that comes out of Projectile Factory.

5. Optional: Test It!

It works! The Console shows debug log messages that are very bright. I set it up like this to draw your attention to the portions of the code that pass the damage back and forth. You can set up your logic however you'd like, of course!

You're Done!

Next, check out how you can quickly use the 3rd Party Integrations we have provided on the Asset Store. If you have the particle package as well, you'll find ready-to-use Projectiles that work with the particles from each package!

Use 3rd Party Integrations
It works!