Animals Controller + Invector


Let's make any creature controlled by the Animal Controller to attack the Invector character.

For this quick guide I'll be using the Poly Art Wolf and the Animal Controller, along with Invector Melee template.

If you are using the Horse animset pro Integration, by default all the Melee weapons can hurt any of my creatures.

Preparing the scene

For a quick Environment; prepare a simple scene with the Invector Character, the Wolf Enemy AI prefab. As the Ground use a simple plane.

  • Set the Plane as Navigation Static and bake the Navigation Mesh, so the AI wolf can walk around.

  • Create 2 or more Waypoints connected to each other.

Waypoint 1 <next target> will be Waypoint 2, Waypoint 2 <next target> will be Waypoint 3.. and so on

This will be the patrol route for the wolf to walk.

Making Invector to Hit the Animals

Make sure you add the Animal Layer to the Damage Layers on the Shooter/Melee Manager

By Default all Invector's weapons can hurt the animals like the horse. But for small animals, When the Player is swinging the melee weapon, the HitBoxes of that weapon will miss small animals.

This is solved by Increasing that Hit Box collider on Each Weapon


All projectiles should have the Damage Malbers component attached to it an connected to the VDamage Event.

In case of the Arrows add the Damage Malbers Component to the Animated Arrow GameObject and set the Stat you want to affect.

Connect the DamageMalbers.DealDamage method to the Arrow Projectile On Pass damage Event

Do the same for the bullets prefabs

Making the animal to hurt Invector

In order for the animal to make damage to the invector character:

  • We need to add to each Attack Trigger, the VObject Damage component from invector:

  • On the MAttack Trigger Component, use the On Attack Begin && On Attack End events to enable and Disable the VObject Damage script.

  • Make sure the VObject Damage component is disabled by default

Do the same for all Attack Triggers that the animal has. In case of the Poly Art wolf, repeat this step for the Mouth Attack Trigger.

Setting Invector Character as the Main Player

The fastest way to create a Global reference, that can be recognized by the Brain component of the Animal, is adding a Transform Hook.

  • Add the Transform Hook Component to Invectors Character

  • As Hook use the <Player> Asset and as Reference, leave it as the Root of the Character.

Use also the AI Target component to set the Stopping distance for the Character. That way the animal will stop when it gets to the stopping radius.

Checking when Invector Character dies

We need to let the animal knows when the character dies. Luckily Invector has a public unity Event that is invoked when the character is death. We can use this to store a bool value for the Death into a Bool Var Listener component.

  • Add a bool var listener component to Invectors Character. Set the Value to false and the ID to 10

You can add a description to any Var Listener component with the context menu -> Show Description

  • Connect the On Death Event from the Invector Third Person Controller to the bool Var Listener

Using the BoolVarListener.Value = true

That way we can store the Death value and use it on the Animal Brain AI States.

Animal AI States

Finally we need to have the AI States, Tasks and Decisions needed to make a simple Enemy behaviour for the Animal.

To check which current state is using the Animal you can select the AI gameObject inside the animal hierarchy and find the Brain Component.

We can use as a base the States given on the Enemy samples.

01 AC Patrol

This AI State will execute the Patrol behaviour on the waypoints we create on the scenes.

As for the decisions we need to modify Look for Player. Instead of searching for the Animal Player, search for a Transform Var and set the Player asset as the Value.

Changing this we will be looking for the Player Hook we created earlier โ†‘

02 Attack and Kill

This state is in charge of Playing the Attack animations near the current target the Ai Animal has.

In this AI State, we can't use the default <Is Target Death> decision. Since this decision is use only for characters that uses the Animal Controller.

Instead, create a new Decision, this time a <CheckVarListener> decision. We will be checking if the target has a bool var Listener and if its value has changed to true. Which means the Invector Character is death.

You can create a new Decision using the Create context menu on the project window.

Specify the Listener ID to be equal to 10 so matches the ID we set before โ†‘.

03 Find who hurt me

This state is use in case the animal has suffer any damage, so it looks if the player is near him, and if is near then it will go to the Attack State.

For this state, the <Is Player near me> decision needs to be modified too, just like the <Look for Player> Decision in the first AI State.

Setting the Waypoints as patrol route

Finally select the animal, and on the AI GameObject, set any of the waypoints to the first Target on the AIANimal Control component

And that's it, that way the animal can attack Invector's Character.

Last updated