05 Enemy: Chomper

In this tutorial we’ll set up the first enemy.

The first enemy we’ll set up is the Chomper, a small enemy with a melee attack (we’ll set that up in the next tutorial).

There are multiple things to do, beside setting up the combatant itself – we’ll set up:

  • idle schematic (used by the move AI)
  • animations
  • move AI
  • combatant
  • scene setup (spawn, etc.)

Let’s get to it.

Idle Schematic #

We’ll start with setting up a simple schematic that defines the idle behaviour when the combatant reached a waypoint (using it’s move AI).

The combatant will simply wait for a random time.

Navigate to Schematics and start working on a new schematic.

Wait #

Add Node > Base > Wait

We’ll wait between 1 and 5 seconds.

  • Time
    Select Value > Random.
    Set the first value to 1.
    Set the second value to 5.

And that’s it for the schematic. Click on Save Schematic to save it, e.g. as IdleWait.

Animations #

We’ll continue with the animation set up of the comper (including an animation for another enemy that’s nearly the same).

The animator controller’s setup is the same as for the player – i.e. idle/movement is handled by a blend tree and other animations are played directly.

Navigate to Base/Control > Animations and add a new animation setup.

  • Name
    Set to Chomper.

Mecanim Settings #

The enemy is moved by a NavMesh Agent component (movement targets are found by the move AI we’ll set up). We’ll forward the movement speed to the animator as a parameter.

  • Set Horizontal Speed
    Enable this setting.
  • Horziontal Parameter
    Set to Speed.

We’ll set up animations for damage, death and 2 attacks.

Mecanim Animation 0 #

Click on Add Mecanim Animation.

  • Animation Type
    Select Damage.

Adjust the already added Animation 0.

  • State Name
    Set to ChomperHit1.
  • Duration Type
    Select Animation Clip.
  • Use State Name
    Enable this setting.
  • Play Mode
    Select Play.

Copy the Animation 0 setup.

  • State Name
    Set to ChomperHit2.

Mecanim Animation 1 #

Click on Add Mecanim Animation.

  • Animation Type
    Select Death.

Adjust the already added Animation 0.

  • State Name
    Set to ChomperHit3.
  • Duration Type
    Select Animation Clip.
  • Use State Name
    Enable this setting.
  • Play Mode
    Select Play.

Mecanim Animation 2 #

Copy Mecanim Animation 1.

  • Animation Type
    Select Attack.
  • State Name
    Set to ChomperAttack.

Mecanim Animation 3 #

Copy Mecanim Animation 2.

  • Animation Type
    Select Attack 2.
  • State Name
    Set to SpitterSpit.

Move AI #

The move AI is used to detect enemy targets, patrol around or find points of interest. The move AI itself only finds positions to move to, the actual movement is handled by the combatant’s movement component setup (we already set it up to use NavMesh Agent components).

The chomper should try to move to the back of the player, while keeping a small distance (until it’s time to attack), i.e. we’re using a Caution setup. It’ll also detect points of interest, which we’ll later use to lure it to grenades.

You can learn more about move AIs in this documentation.

Navigate to Combatants > Move AI, we’ll change the Default move AI.

Base Settings #

  • Name
    Set to Chomper.

Auto Stop Settings #

These settings are used to prevent the combatant from getting stuck, e.g. trying to move somewhere they can’t reach.

We’ll slightly adjust this.

  • Use Auto Stop
    Enable this setting.
  • Stop Distance
    Set to 0.01.
    If the combatant moved less than this for a defined amount of time, auto stop kicks in and stops the current movement.
  • Stop Time
    Set to 1.
    Auto stop kicks in after 1 second.

Speed Settings #

These settings handle which speed is used to move for different movement actions, e.g. hunting or moving to waypoints. The speed is based on the combatant’s movement speed setup, but also has a fallback value in case no move speed could be calculated.

We’ll only adjust the waypoint speed.

  • Speed Type (Waypoint Speed)
    Select Walk.

Waypoint Settings #

These settings handle the combatant’s patroling – we’ll use random patrols and also allow detecting points of interest.

  • Enable Random Patrol
    Enable this setting.
  • Patrol Radius
    Set to 5.
  • From Current Position
    Enable this setting.
    The patrol radius is used from the combatant’s current position instead of it’s spawn position.
    Disabling this setting can be used to limit the combatant’s movement to a radius around it’s spawn position.

We’ll also use a raycast to check if the random patrol position is not available. This’ll use No Random Patrol components on our blocking scene architecture (we’ll set that up with the combatant spawn in the scene).

The default Raycast Distance and Raycast Height Offset are already how we need them.

  • Use Raycast
    Enable this setting.
  • Layer Mask
    Select only the Default layer.
    First select Nothing, then select Default.
    Our level architecture is only on the Default layer.

Points Of Interest #

We’ll use points of interest, which should already be enabled.

We don’t need to limit the detection tags (you can use tags on points of interest to have a move AI only react to defined PoIs), i.e. the move AI will detect all PoIs.

  • Use Points Of Interest
    Enable this setting.
    This should be enabled by default.

Idle Settings #

These settings define the combatant’s behaviour when reaching a waypoint.

You can use schematics to do whatever you want – we’ve already set up a simple schematic to wait for a random time.

  • Enable Idle
    Enable this setting.

Click on Add Idle Schematic.

  • Schematic Asset
    Select the IdleWait schematic.

Enemy Detection #

These are the most crucial settings – they handle if and how enemies are detected.

  • Use Detection
    Enable this setting.
  • Detect On Damage
    Enable this setting.
    The player will be detected when hitting the enemy.
  • Range (Base Detection Range)
    Select Value > Value.
    Set the value to 10.
    Enemies within 10 world units can be detected by the move AI.

Click on Add Detection.

Move Detection 0 #

Move detection settings handle how targets are detected.

For this, we’ll detect on sight (also checking line of sight using raycasts) in a 120° forward angle.

  • Detect Combatants
    Enable this setting.
  • Detect Points of Interest
    Disable this setting.
    We’ll use a separate detection for PoIs.
  • Type
    Select Sight.
  • Use Raycast
    Enable this setting.
  • Layer Mask
    Select only the Default layer.
    First select Nothing, then select Default.
  • Use Child (User)
    Set to Head.
  • Use Child (Target)
    Set to Head.
  • Angle
    Set to 120.

Move Detection 1 #

If an enemy is really close (within 1 world unit), we’ll detect it in any case.

Click on Add Detection to add a new move detection.

  • Detect Combatants
    Enable this setting.
  • Detect Points of Interest
    Disable this setting.
  • Type
    Select Sight.
  • Additional Range Check
    Enable this setting.
  • Range
    Select Value > Value.
    Set the value to 1.
  • Angle
    Set to 360.

Move Detection 2 #

The last detection is for points of interest.

Click on Add Detection to add a new move detection.

  • Detect Combatants
    Disable this setting.
  • Detect Points of Interest
    Enable this setting.
  • Type
    Select Sight.
  • Angle
    Set to 360.

Target Position Check #

These settings handle updating the target’s position – depending on the distance we’ll update the position in different intervals.

  • Target Lost Interval
    Set to 5.
    Targets are lost after 5 seconds of not detecting them.
  • Lost Position Check
    Enable this setting.
    The target’s position is still updated while it’s not detected.

There’s already a Check 0 set up for us, we’ll adjust it.

  • Interval
    Set to 0.
  • Minimum Distance
    Set to 0.

Copy Check 0.

  • Interval
    Set to 0.1.
  • Minimum Distance
    Set to 1.

Copy Check 1.

  • Interval
    Set to 0.2.
  • Minimum Distance
    Set to 5.

Copy Check 2.

  • Interval
    Set to 0.5.
  • Minimum Distance
    Set to 10.

Caution Settings #

The caution mode hunts the target, but keeps a defined distance.

  • Use Caution
    Enable this setting.
  • Use Target Change
    Enable this setting.
    The target can be changed if a closer target is detected.

Critical Range #

If the target comes closer than this range, the combatant will move away.

  • Range
    Select Value > Value.
    Set the value to 1.
  • Threshold
    Select Value > Value.
    Set the value to 0.5.

Stop Range #

This defines how far away the combatant stops hunting the target. We’ll also set a stop angle, which allows us to move to the target’s back.

  • Range
    Select Value > Value.
    Set the value to 3.
  • Threshold
    Select Value > Value.
    Set the value to 0.5.
  • Use Action Range
    Enable this setting.
    This’ll overrule the stop range with an action’s use range, e.g. the comper’s attack range (we’ll set that up in the next tutorial).
  • Use Stop Angle
    Enable this setting.
  • Local Space
    Enable this setting.
    The angle is calculated in the target’s local space.
  • Stop Angle
    Set to 180.
    I.e. we’ll try to reach the target’s back.

Combatant #

Now, we can finally set up the actual combatant.

Navigate to Combatants > Combatants and add a new combatant.

  • Name
    Set to Chomper.

Base Settings #

  • Combatant Type
    Select Default.

Prefab Settings #

  • Prefab
    Select Chomper Variant.
    You can find the prefab in Assets/Tutorial Assets/Prefabs/Combatants/.

Status Settings #

  • Class
    Select Default.

Status Value Settings > Start Values #

Click on Set Default, this adds all Normal type status values (e.g. Max HP, ATK, etc.) with their default initial value.

We now only need to adjust the values as we want them. I’ll just list the status values and their names here – you need to change the Start Value setting of the corresponding status value.

  • Max HP
    Set to 18.
  • Max Stamina
    Set to 1.
  • ATK
    Set to 3.
  • RATK
    Set to 1.

Animations & Movement #

We’ll now add the animations we set up, set up the move speed used by the chomper and the move AI.

Animations #

Click on Add Animations.

  • Animations
    Select Chomper.

Movement Settings > Move Speed #

  • Own Move Speed
    Enable this setting.
  • Walk Speed
    Select Value > Value.
    Set the value to 2.
  • Run Speed
    Select Value > Value.
    Set the value to 4.
  • Sprint Speed
    Select Value > Value.
    Set the value to 8.

Movement Settings > Move AI #

  • Own Move AI
    Enable this setting.
  • Use Move AI
    Enable this setting.
  • Move AI
    Select Chomper.

Sound Settings #

Click on Add Sound.

  • Sound Type
    Select Attack.
  • Audio Clip
    Select creature_roar_01.

Copy Audio Clip 0.

  • Audio Clip
    Select creature_roar_02.

Copy Audio Clip 1.

  • Audio Clip
    Select creature_roar_03.

Click on Add Sound to add another sound setup.

  • Sound Type
    Select Death.
  • Audio Clip
    Select creature_die_01.

Save Changes #

That’s it for the setup in the editor.

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

Scene Setup #

Open the Scene scene (found in Assets/Scenes/) if it’s not already opened.

We’ll add a Real Time Battle Area to have an ongoing real time battle in the whole scene, Block Combatant Spawn and No Random Patrol components to the scene’s architecture, and use a Combatant Spawner to spawn a few of our chompers.

Add Real Time Battle Area #

Use either the scene hierarchy context menu (ORK Framework > Battle > Real Time Battle Area (Scene)) or the scene wizard to add a Real Time Battle Area component (on an empty game object) to the scene.

It doesn’t really matter where you place the game object, the scene wide area (without using a collider to limit the area) is used for the whole scene.

Add Block Components #

The Block Combatant Spawn component is used to prevent combatants from spawning where they shouldn’t.

The No Random Patrol component is used to prevent combatants from patroling where they shouldn’t.

They can be used in two ways:

  • with a collider (used as trigger) to define an area
  • on scene architecture to be recognized when hit by raycasts (for spawn/patrol positions)

We’ll use the raycast way.

The level’s architecture has certain parts that should block movement and not be accessible to the combatants.

If you look at the scene hierarchy, you’ll notice that all of that is grouped under the Vegetation and Blocking Architecture game objects.

Add a Block Combatant Spawn and a No Random Patrol component to both of them using the component menu. That’s all you need to do.

If you take a look at their settings, their raycasting options are already set up for us (default setup) to be used by raycast checks and also use it’s child objects. I.e. if any of the blocking architecture (all have colliders attached) is hit by a raycast for combatant spawning or random patrols, they’ll be blocked automatically.

Add Combatant Spawner #

Now, we’ll spawn our chompers using Combatant Spawner components.

Add a spawner to the upper right part of the scene, in the area below the rock the player spawns on.

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)).

We’re using the variant without a collider, because we’ll add a Sphere Collider instead of the default Box Collider that’s otherwise used.

Rename the game object to Chompers and change the game object’s layer to Ignore Raycast.

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

Combatant Settings #

A combatant is already added for us, let’s set it up.

  • Faction
    Select Enemies.
  • Use Group
    Disable this setting.
  • Combatant
    Select Chomper.
  • Quantity
    Set to 2.
  • Respawn
    Enable this setting.
  • Respawn Time
    Set to 60.
    Enemies will respawn after 1 minute.
    Feel free to change the time to your liking.

Spawn Settings #

We’ll enable spawning directly on the NavMesh.

  • Use NavMesh Positions
    Enable this setting.
  • Sample Distance
    Set to 1.
  • Area Mask
    Set to -1.
    This’ll allow using all areas.

Start Settings #

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

Add Sphere Collider #

Use the component menu to add a Sphere Collider to the game object.

  • Is Trigger
    Enable this setting.
  • Radius
    Set to 12.

Copy the spawner #

Duplicate the spawner we just set up and move it a bit away from the other.

E.g. I’m placing them like this:

Since we don’t use Scene IDs to remember their state, copying them is no issue at all.

That’s it, save the changes we made in the scene.

Testing #

Hit play and check in on the chompers.

They’re spawning … but they don’t move. And we can’t hit them.

Why? Well, we can’t hit it because we didn’t set up the damage dealer on the chomper yet.

And it doesn’t move because the (now) ongoing real time battle doesn’t allow using the move AI. We need to set that up in the next tutorial.

 

Next, we’ll set up the chomper’s attack!