Graphics Reference
In-Depth Information
followTarget= theTransform;
}
public virtual void Update ()
{
// make sure we have initialized before doing anything
if( !didInit )
Init ();
// check to see if we're supposed to be controlling the player
if( !AIControlled )
return;
// do AI updates
UpdateAI();
}
public virtual void UpdateAI()
{
// reset our inputs
horz=0;
vert=0;
int obstacleFinderResult= IsObstacleAhead();
switch( currentAIState )
{
// -----------------------------
case AIState.moving_looking_for_target:
// look for chase target
if( followTarget!=null )
LookAroundFor( followTarget );
// the AvoidWalls function looks to see if there's
// anything in front. If there is, it will
// automatically change the value of moveDirection
// before we do the actual move
if( obstacleFinderResult==1 ){ // GO LEFT
SetAIState( AIState.stopped_turning_left );
}
if( obstacleFinderResult==2 ){ // GO RIGHT
SetAIState( AIState.stopped_turning_right );
}
if( obstacleFinderResult==3 ){ // BACK UP
SetAIState( AIState.backing_up_looking_for_
target );
}
// all clear! head forward
MoveForward();
break;
case AIState.chasing_target:
// chasing in case mode, we point toward the target
// and go right at it!
// quick check to make sure that we have a target
// (if not, we drop back to patrol mode)
if( followTarget==null )
Search WWH ::




Custom Search