Game Development Reference
In-Depth Information
The behavior tree is now complete. All we need to do now is fill in the script that gets
our
TargetPoint
, so it knows where to move.
RAIN AI custom wander scripts
To start creating our needed wander scripts, first select the
Select Next Target
ac-
tion in the behavior tree. Under the
Class
property, set it to
Create Custom Action
,
which pops up a box to define the script. The following screenshot shows what a
RAIN custom action creation dialog looks like:
Set the name to
SelectRandomTarget
and the script to
CSharp
. This will gener-
ate the default custom action script file already filled with a few common methods. In
this demo, we only need to use the
Execute
function:
public override ActionResult Execute(AI ai)
{
var loc = Vector3.zero;
List<RAINNavigationGraph> found = new
List<RAINNavigationGraph>();
do
{
loc = ai.Kinematic.Position;
loc.x += Random.Range(-8f, 8f);
loc.z += Random.Range(-8f, 8f);
found =
NavigationManager.Instance.GraphsForPoints(
ai.Kinematic.Position,
loc,
ai.Motor.StepUpHeight,
NavigationManager.GraphType.Navmesh,