UnrealScript Game Programming Cookbook

(Chris Devlin) #1
Chapter 5

147

Begin:


// If we can reach our pawn....
if(NavigationHandle.ActorReachable(target))
{
/* Clear any debug lines that would otherwise be
drawn
/
FlushPersistentDebugLines();


/* Move directly toward our pawn /
MoveToward(target,target);
}
else if( FindNavMeshPath())
{
// Our end goal is to reach our pawn
NavigationHandle.SetFinalDestination
(target.Location);


/* Clear any debug lines that would otherwise be
drawn
/


FlushPersistentDebugLines();
// Draw lines for how to reach our pawn
NavigationHandle.DrawPathCache(,TRUE);


// Move to the first node on the path
if(NavigationHandle.GetNextMoveLocation
(TempDest, Pawn.GetCollisionRadius()))
{
// Draw the line to our pawn
DrawDebugLine(Pawn.Location,TempDest,255,0,0,true);


/* Draw a red sphere to illustrate the next
location the bot will stop at
/
DrawDebugSphere(TempDest,16,20,255,0,0,true);


/* Move directly to this red sphere, without
pathfinding
/


MoveTo(TempDest, target);}
}
else
{
/* We can't follow the pawn, so exit this state
otherwise we'll enter an infinite loop.
/
GotoState('Idle');
}
// Go back to the beginning of this state
goto 'Begin';
}

Free download pdf