Using Battle components to define battle locations for unplaced battles.

You’re using Random Battle Areas or Combatant Spawners for battles in your game? Depending on where a random battle starts or an enemy combatant catches the player, the battle’s position and placement of the combatants might not be ideal – they could end up fighting around a big tree or in a position where the camera’s view is blocked by something.

To prevent this, you can use the Use Nearest Battle setting in Random Battle Areas and Combatant Spawners. This will automatically use the nearest game object with a Battle component attached for the battle, which allows you to define places where battles will take place.

This tutorial is based on the game tutorial series – we’ll place battles for the Active Time combatant spawner to only have the battles take place on the road and not in the woods.

Placing Battles

First, we’ll create an empty game object (e.g. using the Unity menu: GameObject > Create Empty) and name it Battle Position. Add a Battle component (Add Component > ORK Framework > Battles > Battle) and change the following settings.

  • Use Scene ID
    Disable this setting.
  • Start Type
    Select None.

That’s all we need to change – things like the Battle Type or the participating combatants will be coming from the Combatant Spawner. If you like, you can define battle spots or using different battle start/end events in the Battle component.

Next, we’ll place the new game object and several copies along the road of the Active Time combatant spawner.

gameplay_20_nearest_battle1

I’ve used 8 battle positions in total and placed them at the following positions:

  • X=274, Y=21, Z=423
  • X=264, Y=19, Z=426
  • X=255, Y=16, Z=425
  • X=245, Y=12, Z=426
  • X=233, Y=8, Z=427
  • X=221, Y=6, Z=432
  • X=207, Y=5, Z=436
  • X=195, Y=3, Z=439

All game objects use the following rotation:

  • X=0, Y=90, Z=0

Changing the Combatant Spawner

Now, all we need to do is change the combatant spawner to use the nearest battle game object. All combatants spawned by the combatant spawner will use this setting and find the nearest battle game object (within a defined range) for the battle to take place when they catch the player.

Select the Combatant Spawner Area 0 game object in the scene and change the following settings.

Battle Settings

  • Use Nearest Battle
    Enable this setting.
  • Nearest Range
    Set to 50.

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

Testing

When testing the game now and you run into one of the combatants spawned by the Active Time combatant spawner, the battle will take place somewhere on the road.

gameplay_20_nearest_battle2

In case one of the battle positions still isn’t ideal, you can just move that game object to a better position.

Tip: Remembering Position

If you want the player to return to the position he was when the battle started you can use a similar technique as used in the battle in a different scene tutorial.

In the Battle Start Event, use a Set Scene Position step to store the player’s position (Player Group actor).

In the Battle End Events, use a Change Position step to change the player’s position (Player Group actor), using the Scene Position value type for the position.

Alternatively, this can also be done using a global Vector3 game variable.