Graphics Reference
In-Depth Information
MoveForward();
if( faceWaypoints )
{
TurnTowardTarget
( currentWaypointTransform );
}
}
break;
case AIState.steer_to_waypoint:
// make sure we have been initialized before trying
// to access waypoints
if( !didInit && !reachedLastWaypoint )
return;
UpdateWaypoints();
if( currentWaypointTransform==null )
{
// it may be possible that this function gets
// called before waypoints have 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.InverseTransform
Point( currentWaypointTransform.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 );
// now we do the same for torque, but make sure that
// it doesn't apply any engine torque when going
// around a sharp turn...
if ( Mathf.Abs( horz ) < 0.5f ) {
vert= RelativeWaypointPosition.z / Relative
WaypointPosition.magnitude - Mathf.Abs( horz );
}else{
NoMove();
}
break;
case AIState.steer_to_target:
// make sure we have been initialized before trying
// to access waypoints
if( !didInit )
return;
if( followTarget==null )
Search WWH ::




Custom Search