AI System Updates

Read Time:2 Minute, 20 Second

I added a throttle to the Movement Animator so that characters can be set to walk or run. In the interest of keeping the Animator complete separate from the Agent and AI code, Mover also received two new methods called Walk and Run which invoke events of the same name exposed to the inspector:

These controls can be used before Mover.GoTo calls to set the maximum speed of the Nav Mesh Agent according to the speed settings in the Movement Animator component (or whatever custom component is put in its place.


Added a Restart method to the Action base class. Restart is called by the Brain when an Action is removed from the stack and set as the current Action.


The Restart method was added specifically because the Patrol Action needed it in order to resume moving to the correct Waypoint. The previous behavior would send the character to the next Waypoint rather than the current one.

I added a component called Waypoint which sits on the Game Objects in a Waypoint Path. The Waypoint has a reference to an Action that the patrolling character will execute when that waypoint is reached.

In the revised Patrol, the character will wait for 5s in the town,
2s on either of the nodes on the path, and 0s on the stairs.

Patrol checks if the Mover has reached its destination. When it does and if the Waypoint has an Action set, then it calls Set Action on the Brain and sets the next Waypoint to be the current Waypoint. Go To Waypoint is not called until Restart is called by the Brain.

If no Action is set then Patrol calls Go To Waypoint.


I want to stop a character from moving or rotating while an attack is being executed. The first step is to extract the rotation code from the Attack code. I moved the rotation code to the Focus component. Rotation will be handled by the Attack Target component.

Let’s talk about the Attack Target sequence.

  1. Execute has multiple guards to bail should the Attacker already be Attacking or if the Target is null, dead, or the Attacker.
  2. The range between the Attacker and the Target is calculated. If the Target is in range then the Mover is set to Idle and the angle to the Target is calculated. If the angle is inside the Attack arc then the Attacker executes the current Attack. Otherwise, the Focus rotates the Attacker to face the Target.
  3. If the range to the Target exceeds the chase range and the attack has a chase Action then that Action replaces the attack Action. Otherwise, the attack Action is cleared.
  4. If the range to the Target is inside the chase range then the Attacker moves toward the Target at a run.

Happy
Happy
0 %
Sad
Sad
0 %
Excited
Excited
0 %
Sleppy
Sleppy
0 %
Angry
Angry
0 %
Surprise
Surprise
0 %

Average Rating

5 Star
0%
4 Star
0%
3 Star
0%
2 Star
0%
1 Star
0%

Leave a Reply

Your email address will not be published. Required fields are marked *