Graphics Reference
In-Depth Information
SetAIState( AIState.moving_looking_for_
target );
// the TurnTowardTarget function does just that, so
// to chase we just throw it the current target
TurnTowardTarget( followTarget );
// find the distance between us and the chase target
// to see if it is within range
distanceToChaseTarget= Vector3.Distance( myTransform.
position, followTarget.position );
// check the range
if( distanceToChaseTarget>minChaseDistance )
{
// keep charging forward
MoveForward();
}
// here we do a quick check to test the distance
// between AI and target. If it's higher than
// our maxChaseDistance variable, we drop out of
// chase mode and go back to patrolling.
if( distanceToChaseTarget>maxChaseDistance ||
CanSee( followTarget )==false )
{
// set our state to 1 - moving_looking_for_
// target
SetAIState( AIState.moving_looking_for_
target );
}
break;
// -----------------------------
case AIState.backing_up_looking_for_target:
// look for chase target
if( followTarget!=null )
LookAroundFor( followTarget );
// backing up
MoveBack ();
if( obstacleFinderResult==0 )
{
// now we've backed up, let's randomize
// whether to go left or right
if( Random.Range (0,100)>50 )
{
SetAIState( AIState.stopped_turning_
left );
} else {
SetAIState( AIState.stopped_turning_
right );
}
}
break;
Search WWH ::




Custom Search