BATTLE 06 Random Battles

In this tutorial we’ll add random battle areas to our scene.

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

We’ve already plastered the north half of the World scene with battles, using Combatant Spawners to have enemies hunt down the player.

Let’s do something different for the south half – love them or hate the, but random battles are a staple of classic RPGs.

Open the World scene (Assets/Scenes/).

Adding Random Battles #

You can add random battles to your scene using the Random Battle Area component – when the player moves within the random battle area’s trigger (collider with Is Trigger enabled) there’s a chance a random battle will start.

We’ll make it simple and just add one giant random battle area to cover the whole area from the outpost’s entry to the mountains by the swamp.

Create a Random Battle Area either using the scene hierarchy context menu (ORK Framework > Battle > Random Battle Area (3D)) or the Makinom scene wizard (Create Game Object > Random Battle Area 3D).

This’ll create a new game object with a Box Collider and a Random Battle Area component. Let’s adjust it to our needs.

Box Collider #

The collider defines the area in which random battles are started.

Mine has the following size:

  • Is Trigger
    Enable this setting.
    Should be enabled by default with the created setup.
  • Size
    Set to X=350, Y=100, Z=250.

That should be a good size to cover the area. Move the game object a bit to end before the outpost’s fence and before the bridge crossing the river (see image above for reference).

Random Battle Area #

Now, let’s set up how often a random battle happens and which enemies can appear.

Random Battle Settings #

  • Use Nearest Battle
    Enable this setting.
    This allows us to place battle arenas that can be used for our random battles.
    Depending on the player’s position, it’ll search for a nearby battle within a defined range.
  • Nearest Range
    Set to 20.
    The default range should be enough for us.

The Random Chance Settings in combination with the distance settings determine how often a battle happens. We’ll keep the default settings for battle chance and check interval.

  • Battle Chance
    Set to 10.
    There’s a 10% chance to start a battle when checked.
    Seems pretty high on it’s own.
  • Check Interval
    Set to 0.5.
    The time between performing 2 checks.
    I.e. there are 2 checks per second possible.

We’ll control how often a battle starts via the distance settings by using a higher move and maximum distance.

  • Minimum Move Distance
    Set to 0.5.
    The player needs to move at least 0.5 world units between checks.
  • Minimum Distance
    Set to 5.
    The next battle can start after the player has moved at least 5 world units.
  • Maximum Distance
    Set to 100.
    A battle will start without check if the player moved for 100 (or more) world units since the last battle.

Combatant Settings #

We’ll add multiple groups that will be used for random battles. Which one is used is determined by a chance check – each combatant/group we add defines the chance it has to occur.

The total of all chances should be 100 to have a full range of possible enemies. However, you can also define less or more – less would mean that if no enemy was found, no battle occurs. More, well, all exceeding the maximum chance (100 for all chance checks, can be changed in Game > Game Settings) would never occur. You can see the total chance of all added combatants/groups at the top of the component’s settings.

Let’s get to it. We’ll begin with editing the already added Combatant 0.

  • Chance
    Set to 30.
  • Faction
    Select Enemy.
  • Use Group
    Enable this setting.
  • Combatant Group
    Select 1x Random.

Copy the Combatant 0 setup and change the following settings.

  • Chance
    Set to 10.
  • Combatant Group
    Select 1x Tank, 1x Physical DPS.

Copy the Combatant 1 setup and change the following settings.

  • Combatant Group
    Select 1x Tank, 1x Supporter.

Copy the Combatant 2 setup and change the following settings.

  • Combatant Group
    Select 1x Tank, 1x Mage.

Copy the Combatant 3 setup and change the following settings.

  • Combatant Group
    Select 1x Physical DPS, 1x Mage.

Copy the Combatant 4 setup and change the following settings.

  • Combatant Group
    Select 2x Physical DPS.

Copy the Combatant 5 setup and change the following settings.

  • Chance
    Set to 5.
  • Combatant Group
    Select 1x Tank, 2x Physical DPS.

Copy the Combatant 6 setup and change the following settings.

  • Combatant Group
    Select 1x Tank, 1x Physical DPS, 1x Mage.

Copy the Combatant 7 setup and change the following settings.

  • Combatant Group
    Select 1x Tank, 1x Physical DPS, 1x Supporter.

Copy the Combatant 8 setup and change the following settings.

  • Combatant Group
    Select 1x Tank, 1x Mage, 1x Supporter.

That sums up to 100 percent – 30% chance to fight 1 enemy, 50% chance to fight 2 enemies, 20% chance to fight 3 enemies.

That’s it for the random battle setup. Save the changes to the scene.

Testing #

Hit play, run over to the random battle area (maybe also save at the fox statue to be able to load from there) and run around until a battle starts.

A battle starts and we fight right where we are at that moment. So far so good.

However, this could lead to situations where a battle starts in places that are not so good, e.g. placing combatants up a cliff, or just with a tree in the middle of the battle.

Let’s fix that using placed battles.

Placing Battles #

We arleady set up our random battle area to use the nearest battle it can find within a range. All we need to do is place battles for that, i.e. game objects with a Battle component attached, like we already used for our spawned combatants.

You can create ready to use none battles either using the scene hierarchy context menu (ORK Framework > Battle > Battle (None)) or the Makinom scene wizard (Create Game Object > Battle (None)).

The created battle is set up with disabled scene ID, without any combatants and no start type to start it. Perfrect for use by other components, e.g. our random battle area.

Place some battles at various positions – you can place them all over if you want, though it’s enough to have a few available for testing.

Tip: Keep things organized

With all those placed battles in your scene, there’ll be a lot of game objects cluttering your scene hierarchy list.

Parent them to the Random Battle Area to keep them out of the way and bundled together with the game mechanic they’re connected to.

Alternative: Teleport Battles #

Alternatively, you can also fight in a different scene. For this, you can use a battle start schematic that loads the battle scene and battle end schematics that load back into the previous scene.

See these tutorials on battle start and battle end schematics, which have examples for teleport battles.

If you’re going for teleport battles, you don’t need to do the rest of this tutorial (adjusting the battle start/end schematics).

Testing, again #

Hit play again, run around an area you placed a battle until a battle starts. The battle starts and you’re placed at your pre-placed battle instead of fighting wherever you where.

Great … however, when the battle ends, you stay at the location of the battle (unless you used teleport battles, in which case you’re done with this tutorial).

This was fine for our spawned combatants, since the threat was over after the battle (until they respawned), but with random battles, this could be quite frustrating.

Adjusting Battle Start/End Schematics #

Let’s remember the position the player was when the battle starts and return to it after the battle. In case you’re using teleport battles, you’ll not need to do this – also, this uses a different functionality than the teleport battles, as we don’t reload the scene, just spawn/place the player back at it’s previous position.

We’ll need to adjust the battle start and 2 battle end schematics (victory and escape).

Battle Start Schematic #

First, we’ll change the BattleStart schematic – open it and change the following.

Set Scene Position #

Add Node > Game > Scene > Set Scene Position

This node sets a position and rotation that can be used to spawn the player – it’s not the same as storing the current scene.

You can save one position per scene.

Add the node between the Settings and Store Music nodes.

  • Current Scene
    Enable this setting.
  • Use Game Object
    Enable this setting.
  • Object
    Select Player.

That’s it – don’t forget to save the changes.

Battle End Victory/Escape Schematic #

For both the BattleEndVictory and BattleEndEscape schematics, we’ll do the same setup.

The new nodes are added before the last Fade Screen node.

Spawn ORK Player #

Add Node > Game > Player > Spawn ORK Player

We’ll spawn the player at the stored scene position.

  • Spawn At
    Select Scene Position.
    This’ll use the stored scene position of the current scene (if available).

Block Camera Control #

Add Node > Input > Block Camera Control

We’ll unblock the camera control, so that it can update it’s position to the player while the screen is faded out.

  • Block/Unblock
    Disable this setting.

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

Also, remember to do this for both the victory and escape (battle end) schematics.


You can copy nodes between schematics – e.g. select the 2 nodes that where added, copy them to the clipboard (e.g. via CTRL + C) and paste them in the other schematic (e.g. via CTRL + V).

Testing, once again #

Hit play, run around – battle starts.

This time, after you won (or escaped) the battle, you’ll be placed back at your previous position!


Next, we’ll finally enter the dungeon.