Graphics Reference
In-Depth Information
// initialization, which means we need to drop out to avoid
// doing anything silly or before it breaks the game.
if( totalWaypoints==0 )
{
// grab total waypoints
totalWaypoints= myWayControl.GetTotal();
return;
}
if( currentWaypointTransform==null )
{
// grab our transform reference from the waypoint
// controller
currentWaypointTransform= myWayControl.GetWaypoint
( currentWaypointNum );
}
// now we check to see if we are close enough to the current
// waypoint to advance on to the next one
myPosition= myTransform.position;
myPosition.y= 0;
// get waypoint position and 'flatten' it
nodePosition= currentWaypointTransform.position;
nodePosition.y= 0;
// check distance from this to the waypoint
currentWayDist= Vector3.Distance( nodePosition,myPosition );
if ( currentWayDist < waypointDistance ) {
// we are close to the current node, so let's move
// on to the next one!
if( shouldReversePathFollowing )
{
currentWaypointNum--;
// now check to see if we have been all the
// way around
if( currentWaypointNum<0 ){
// just in case it gets referenced
// before we are destroyed, let's
// keep it to a safe index number
currentWaypointNum= 0;
// completed the route!
reachedLastWaypoint= true;
// if we are set to loop, reset the
// currentWaypointNum to 0
if(loopPath)
{
currentWaypointNum=
totalWaypoints;
// the route keeps going in a
// loop, so we don't want
// reachedLastWaypoint to ever
// become true
reachedLastWaypoint= false;
}
Search WWH ::




Custom Search