Graphics Reference
In-Depth Information
same format as user input values would be) so that a player controller script can
use them and deal with turning itself.
9. steer_to_target
This state is similar to steer_to_waypoint except that it does not have any way-
point checking incorporated into it. Instead, it will provide input values for steer-
ing the AI toward its target. There is no obstacle checking in this state either, only
steering.
10. paused_no_target
In this state, the AI does quite literally nothing. It does not move or look for a
target.
As the BaseAIController.cs script encompasses so much functionality, it's is one of
the biggest, if not the biggest, in the topic; there are over 50 lines just in the variable dec-
larations! It may seem rather intimidating at first, but remember that not all of this script
will be running at any one time. Within the main Update() function, we only actually run
whichever segment of code is activated within the case statement, and most of the addi-
tional functions either are there as helper functions for other scripts or are used to set up
the AI with such things as waypoints or enemy target transforms.
9.1 The AI State Control Script
Before getting to the main BaseAIController.cs script, take a look at AIStates.cs below. It
contains all of the AIStates from the previous section stored in an enumerator list similar
to the one used by the character controller from Chapter 5. This list will be used by the AI
to determine its current required behavior. The list is in its own file (the AIStates.cs file)
and in a namespace called AIStates so that we can easily make it accessible from any script
used by the game:
using UnityEngine;
namespace AIStates
{
public enum AIState
{
moving_looking_for_target,
chasing_target,
backing_up_looking_for_target,
stopped_turning_left,
stopped_turning_right,
paused_looking_for_target,
translate_along_waypoint_path,
paused_no_target,
steer_to_waypoint,
steer_to_target,
}
}
Search WWH ::




Custom Search