Graphics Reference
In-Depth Information
if( !didInit )
return;
if( followTarget==null )
{
// it may be possible that this function gets
// called before a target has been set up, so
// we catch any nulls here
return;
}
// now we just find the relative position of the
// waypoint from the car transform,
// that way we can determine how far to the left and
// right the waypoint is.
RelativeWaypointPosition= transform.
InverseTransformPoint( followTarget.position );
// by dividing the horz position by the magnitude,
// we get a decimal percentage of the turn angle
// that we can use to drive the wheels
horz= ( RelativeWaypointPosition.x /
RelativeWaypointPosition.magnitude );
// if we're outside of the minimum chase distance,
// drive!
if( Vector3.Distance( followTarget.position,
myTransform.position )>minChaseDistance )
{
MoveForward();
} else {
NoMove();
}
As this state is following a target around and not traveling along a fixed waypoint
path, it includes some logic to react to obstacles (just in case the target decides to hide
behind a wall or something like that):
if( followTarget!=null )
LookAroundFor( followTarget );
It uses the same code as the obstacle detection in AIState.moving_looking_for_target,
explained earlier in this section:
// 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
TurnLeft ();
}
if( obstacleFinderResult==2 ){ // GO RIGHT
TurnRight ();
}
Search WWH ::




Custom Search