Game Development Reference
In-Depth Information
((BasicNavigator)ai.Navigator).GraphTags);
}
while ( Vector3.Distance(loc,
ai.Kinematic.Position) < 2f
|| found.Count == 0);
ai.WorkingMemory.SetItem<Vector3>("TargetPoint",
loc);
return ActionResult.SUCCESS;
}
In this code, we try to find a good value for the loc variable, a location variable that
is set to a different random location, up to 18 meters away. The found variable iden-
tifies whether a path exists or not. These two things are determined in a loop, which
ends as long as two conditions are met. First, the distance has to be greater than 2,
as the movement should be detected by the player and second, we see if the points
found is greater than zero. If it found none, then we would not be able to get to that
location.
Once the loc variable has a location that works, the next thing it does is use RAIN's
memorysystemandsetsamemoryentry, TargetPoint ,tothenewlocation.Remem-
ber that we have the Move action in our behavior set to find TargetPoint , so Move
will go to our newly found location. Finally, we return a success.
This completes our behavior and script. The last thing we need to do is give that be-
havior to some NPCs and run the game.
Putting NPCs in the RAIN demo
Start by adding another simple NPC character to the game, like we did in the first
chapter. We don't need to add any scripts directly to it. Instead, make sure that the
NPC is selected in the hierarchy, and from the RAIN menu, select Create AI .
In the AI GameObject/component that was added, from the Mind tab, set the Beha-
vior Tree Asset value to RandomWalk , which is found in Assets . Under the anim-
ation tab, click on the Add Existing Animations button.
Search WWH ::




Custom Search