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.
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.
Make sure you add the Animal Layer to the Damage Layers on the Shooter/Melee Manager
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
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
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.
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
- Connect the On Death Event from the Invector Third Person Controller to the bool Var Listener
BoolVarListener.Value = true
That way we can store the Death value and use it on the Animal Brain 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.
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.
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.
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.
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.