16 Follow Me!

In this tutorial we’ll spawn the other player group members in the field and let them follow the player.

The world can be a lonely place if your group members aren’t walking beside you – so let’s change that.

We’ll let the player’s battle group members spawn beside the player, use a move AI to make them follow the player and a formation to follow them in style.

Spawning Player Group Members #

Navigate to Game > Game Settings, this is where the general player group settings are made.

ORK Game Settings > Player/Group Settings #

We’ll simply have to turn on spawning group members.

  • Spawn Group
    Enable this setting.

You can control the distance they spawn from the player using the Distance setting, but that doesn’t concern us, as we’re using a formation to handle that.

If you test now, the battle group members will spawn with the player, but use the default move AI, i.e. not follow the player, randomly moving around.

Formation #

Next, we’ll set up the formation the group will move in. You can learn more about formations in this documentation.

Navigate to Combatants > Formations, we’ll change the Default formation.

  • Name
    Set to Player.
  • Place On Ground
    Enable this setting.
    This’ll use a raycast to find the ground for our positions.
  • Layer Mask
    Select only the Default layer.
    First select Nothing, then select Default.
    Our ground (and other level architecture) is on the Default layer.

Field Positions #

We’ll define the positions our group members will follow their group leader (i.e. the player) here.

Positions can be created in a visual editor – you can add postions using a right-click and move them around using left-click-dragging.

Add 2 positions like this:

For further precision, you can also edit the positions below the formation graph.

Formation Position 0 #

  • Position
    Set to X=-1.5, Y=0, Z=-1.5.
  • Local Space
    Enable this setting.
    This is enabled by default – it makes sure the positions are in local space of the user, i.e. they’ll turn with it.

Formation Position 1 #

  • Position
    Set to X=1.5, Y=0, Z=-1.5.
  • Local Space
    Enable this setting.

Battle Positions #

We’re not going to use the formation in battles. If you want to use it, just add positions to it.

When using a formation for battle, only the leader will be placed using the battle spots, the other group members will be placed according to the used formation.

Formations are not only available for the player, they can also be used by enemies and other AI controlled groups.

Move AI #

Next, we’ll set up the move AI for the player group members. Their move AI will only follow their group leader instead of hunting enemies.

Navigate to Combatants > Combatants and add a new move AI.

  • Name
    Set to Follow Leader.

Group Settings #

These settings manage following the group leader.

  • Follow Leader
    Enable this setting.

Follow Range #

We’ll follow the leader at a distance of 3 world units with a threshold of 0.5.

  • Range
    Select Value > Value.
    Set the value to 3.
  • Threshold
    Select Value > Value.
    Set the value to 0.5.
    This is usually the default threshold.

Give Way #

The combatants can move away from the leader to give them space to move, we’ll use that.

  • Give Way
    Enable this setting.
  • Range
    Select Value > Value.
    Set the value to 1.
  • Threshold
    Select Value > Value.
    Set the value to 0.5.
    This is usually the default threshold.

Auto Respawn #

We’ll automatically respawn combatants when they are too far away.

E.g. in case they get stuck somewhere, this’ll reset them.

  • Auto Respawn
    Enable this setting.
  • Range
    Select Value > Value.
    Set the value to 30.

Prioritise Leader #

We don’t need to use this, since our combatants will only follow the leader and do nothing else.

In case you want to use random patrol (while they’re not following the leader) or other move AI features for the combatants, this can ensure they’ll follow the leader if they are too far away.

Updating Combatants #

We need to set up our player combatants to use the move AI we just created.

Navigate to Combatants > Combatants, we’ll change the following combatants:

  • Warrior
  • Rogue
  • Ranger
  • Wizard
  • Cleric
  • Monk

The setup is the same for all combatants.

Animations & Movement > Movement Settings > Move AI #

  • Own Move AI
    Enable this setting.
  • Use Move AI
    Enable this setting.
  • Move AI
    Select Follow Leader.

Save Changes #

That’s it for the setup so far.

Don’t forget to save your changes by clicking on Save Settings at the bottom of the editor.

Updating Start Game Schematic #

All that’s left to do is actually use the formation we set up. Formations can be used by combatant group setups (Combatants > Combatant Groups), battle AIs and schematics.

We’ll update the Start Game schematic to use the formation.

Open the StartGame schematic we set up at the start of this tutorial.

Change Formation #

Add Node > Combatant > Formation > Change Formation

Add the node before the Spawn ORK Player node, otherwise the group members will not already spawn in formation.

  • Formation
    Select Player.
  • Object (Combatant)
    Select Player.

And that’s it – click on Save Schematic to save the changes.

Testing #

Hit play to test the group spawning.

And they keep following me in formation – great!