BATTLE 05 Spawning Combatants

In this tutorial we’ll spawn combatants in our scene and let them hunt the player.

This tutorial continues the sub-series for setting up battles.

With our hunting move AI set up, we’re ready to let enemies spawn in our scene and hunt the player. A battle will start when coming close to the enemy (as set up by the Auto Start Battles settings in Combatants > Combatants > General Settings).

We still use placed Battle components to define where battles take place, as otherwise we might start a battle at a bad spot, e.g. with a tree in the middle of the combatants.

We’ll set up a prefab with the following things:

  • a move AI range to limit the area the enemy will move and hunt in
  • a battle to place the battle at a position of our choosing
  • a combatant spawner to spawn a combatant

We’ll also add a Level Zone to the scene, which will manage the levels of our enemies.

Let’s get to it – we’ll add combatants to the World scene (Assets/Scenes/).

Prefab Setup #

First, create a Move AI Range, either using the scene hierarchy context menu (ORK Framework > Move AI > Move AI Range (3D)) or the Makinom scene wizard (Create Game Object > Move AI Range (3D)).

Move AI Range Component #

The newly created game object will be the basis for our prefab.

The Move AI Range component’s default setup is already what we need, limiting random patrol and move range.

However, we’ll adjust it’s Box Collider.

Box Collider #

  • Size
    Set to X=40, Y=40, Z=40.

This gives us enough room – we can adjust it for individually placed combatants/battles.

Battle Component #

Add an empty game object to the Move AI Range game object, e.g. rename it Battle.

Add a Battle component to the empty game object via the component menu in the inspector.

  • Use Scene ID
    Disable this setting.
    The battle is only used for placement and doesn’t start on it’s own.

Battle Settings #

  • Can Escape
    Enable this setting.
    Or rather, keep it enabled, unlike the first battle we want to be able to escape.

Combatant Settings #

Remove the added combatant.

It’s not really needed, but just to make sure.

Start Settings #

Click on None.

The battle will not have any start type, as it’ll be started by the spawned combatant getting close to the player.

Combatant Spawner Component #

Add a combatant spawner as a child object of the Move AI Range game object.

Add the combatant spawner either using the scene hierarchy context menu (ORK Framework > Combatant > Combatant Spawner) or the Makinom scene wizard (Create Game Object > Combatant Spawner (Single)).

  • Use Scene ID
    Disable this setting.
    We’ll use respawning, so our combatants will reappear after some time.

Spawner Settings #

  • Battle Component
    Select the Battle component we just added to the other child object.
    E.g. just drag the game object on the field.

Combatant Settings #

A combatant is already added for us, let’s set it up. We can later adjust this for individually placed prefabs.

  • Faction
    Select Enemies.
  • Use Group
    Enable this setting.
  • Combatant Group
    Select 1x Random.
  • Spawn All
    Disable this setting.
    We’ll only spawn the leader of the enemy group instead of all members.
  • Quantity
    Set to 1.
  • Respawn
    Enable this setting.
  • Respawn Time
    Set to 120.
    Enemies will respawn after 2 minutes.
    Feel free to change the time to your liking.
  • Move AI Range
    Select the parent game object’s Move AI Range component.

Start Settings #

The combatant spawner is already set up to spawn on Start, i.e. automatically.

Create Prefab #

With that, our prefab is ready – create a prefab out of the Move AI Range game object, e.g. name it Combatant Spawner Range.

Now, remove the game object from the scene.

Adding Prefabs #

Now, we’ll place prefabs in the scene, rotate them to have the battles align nicely and … just keep doing that to have battles where you want them.

Limit yourself to the forest area, i.e. the green area above the river. E.g. I’ve added prefabs here:

Don’t forget to bring a bit of variation into the used combatants/groups.

Level Zone #

Now, we’ll add a Level Zone to the scene – it’ll be used by the spawned combatants to set their level.

Add the level zone either using the scene hierarchy context menu (ORK Framework > Zome > Level Zone (Scene)) or the Makinom scene wizard (Create Game Object > Level Zone (Scene)).

This’ll create a scene-wide level zone, you can optionally also use a limited zone by adding a collider (used as trigger) to the level zone’s game object.

Level Settings #

We want the enemies to be at the player’s level or slightly above.

  • Set Levels
    Enable this setting.
  • Set Level
    Select Player.
  • Minimum Offset
    Set to 0.
  • Maximum Offset
    Set to 3.

And that’s it – don’t forget to save the scene.

Testing #

Hit play (maybe disable the first battle to avoid it) and run to areas where you placed the combatant spawner prefabs.

Enemies run around and hunt the player if they see him. If they catch the player, the battle starts.


Next, we’ll set up save games.