Graphics Reference
In-Depth Information
{
// 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();
}
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
TurnLeft ();
}
if( obstacleFinderResult==2 ){ // GO RIGHT
TurnRight ();
}
if( obstacleFinderResult==3 ){ // BACK UP
MoveBack ();
}
break;
case AIState.paused_no_target:
// paused_no_target
break;
default:
// idle (do nothing)
break;
Search WWH ::




Custom Search