Spawn a Monster
Contents |
Overview
This tutorial will cover the basics of how to create a script to spawn a Monster when the Player enters a specific area for the first time. It will assume you already have a fundamental understanding of how to navigate and use the GUTS editor along with being familiar with Basic Scripting.
Step-by-Step
Initial Set Up
- Create/Load a level with a pathable area for the Player to walk and Monster Object to spawn.
- Turn Show Helpers on ( Ctrl + H ) to make the logic objects that will be created visible in the editor.
Add Necessary Objects
Right-click on an empty space in the Layout Scene Manager and add the following objects:
- Logic Group
- Logic > Player Sphere Trigger
- Logic > Unit Spawner
Move Objects
- Move the Player Sphere Trigger to a pathable area where the Player should trigger the Monster to spawn.
- Move the Unit Spawner to a pathable area where the Monster should spawn.
Change Properties
Select the Unit Spawner and change the following properties in the Properties Window:
- "Spawn on Create" to False.
- This sets the Unit Spawner to only spawn when it receives a "Spawn Units" Input event instead of automatically on level load.
- "Resource" to "Skeleton".
- This determines the type of Monster to spawn.
- "Count" to 1.
- This is the total number of Monsters to spawn.
Select the Player Sphere Trigger and change the following properties in the Properties Window:
- "Radius" to 4.
- This sets the size of the Player Sphere Trigger. The Player must enter this sphere to trigger it.
Edit Logic Group
Select the Logic Group, open the Logic Editor, and add the Player Sphere Trigger and Unit Spawner objects to the Logic Editor window.
- Specify the "Triggered First Time" Output on the Player Sphere Trigger.
- This Output event is only fired once when the Player enters the Player Sphere Trigger for the first time.
- Specify the "Spawn Units" Input on the Unit Spawner.
- This will spawn the "Resource" set on the Unit Spawner.
Link the "Triggered First Time" Output and "Spawn Units" Input.
Conclusion
When the Player enters the Player Sphere Trigger for the first time the Unit Spawner will spawn the specified Monster. No further Monsters will be spawned if the Player re-enters the Player Sphere Trigger.