document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. class SandboxAIController extends AIController;
  2.  
  3. var Actor target;
  4. var() Vector TempDest;
  5.  
  6. event Possess(Pawn inPawn, bool bVehicleTransition)
  7. {
  8.     super.Possess(inPawn, bVehicleTransition);
  9.     Pawn.SetMovementPhysics();
  10. }
  11.  
  12. //I\'m adding an default idle state so the Pawn doesn\'t try to follow a player that doesn\' exist yet.
  13. auto state Idle
  14. {
  15.     event SeePlayer (Pawn Seen)
  16.     {
  17.         super.SeePlayer(Seen);
  18.         target = Seen;
  19.         GotoState(\'Follow\');
  20.     }
  21. Begin:
  22. }
  23.  
  24. state Follow
  25. {
  26.     ignores SeePlayer;
  27.     function bool FindNavMeshPath()
  28.     {
  29.         // Clear cache and constraints (ignore recycling for the moment)
  30.         NavigationHandle.PathConstraintList = none;
  31.         NavigationHandle.PathGoalList = none;
  32.  
  33.         // Create constraints
  34.         class\'NavMeshPath_Toward\'.static.TowardGoal( NavigationHandle,target );
  35.         class\'NavMeshGoal_At\'.static.AtActor( NavigationHandle, target,32 );
  36.  
  37.         // Find path
  38.         return NavigationHandle.FindPath();
  39.     }
  40. Begin:
  41.  
  42.     if( NavigationHandle.ActorReachable( target) )
  43.     {
  44.         FlushPersistentDebugLines();
  45.         //Direct move
  46.         MoveToward( target,target );
  47.     }
  48.     else if( FindNavMeshPath() )
  49.     {
  50.         NavigationHandle.SetFinalDestination(target.Location);
  51.         FlushPersistentDebugLines();
  52.         NavigationHandle.DrawPathCache(,TRUE);
  53.        
  54.         // move to the first node on the path
  55.         if( NavigationHandle.GetNextMoveLocation( TempDest, Pawn.GetCollisionRadius()) )
  56.         {
  57.             DrawDebugLine(Pawn.Location,TempDest,255,0,0,true);
  58.             DrawDebugSphere(TempDest,16,20,255,0,0,true);
  59.             MoveTo( TempDest, target );
  60.         }
  61.     }
  62.     else
  63.     {
  64.         //We can\'t follow, so get the hell out of this state, otherwise we\'ll enter an infinite loop.
  65.         GotoState(\'Idle\');
  66.     }
  67.     goto \'Begin\';
  68. }
  69.  
  70. DefaultProperties
  71. {
  72. }
');