Game Development Reference
In-Depth Information
17 float CurrentDistance = Vector3.Distance(Target.position,
HR.transform.position);
18
19 //Found nearer health restore, so update
20 if(CurrentDistance <= DistanceToNearest)
21 {
22 Nearest = HR;
23 DistanceToNearest = CurrentDistance;
24 }
25 }
26
27 //Return nearest or null
28 return Nearest;
29 }
Summary
The complete AI project created in this chapter can be found in the topic's companion
files (code bundle) in the ai folder of this chapter. I recommend that you open it and
then test it out. Using the first-person controller, the player can navigate the level,
avoid enemies, and also attack when enemies are in range using the Space bar,
as shown here:
Testing the AI_Enemy class
 
Search WWH ::




Custom Search