document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. class CustomAIController extends AIController;
  2.  
  3. var float speedMod;
  4. var float chaseDistance;
  5. var float distanceToPlayer;
  6. // 2 lines below is essencial for pathfinding
  7. var Actor target;
  8. var Vector selfToPlayer;
  9.  
  10. var float MonsterChasingPlayer;
  11.  
  12. var CustomPawn playerPawn;
  13.  
  14.  
  15. auto state Idle
  16. {
  17.     event SeePlayer(Pawn seePawn)
  18.     {
  19.         if (playerPawn == none)
  20.             playerPawn = CustomPawn(seePawn);
  21.        
  22.         distanceToPlayer = VSize(self.pawn.location - playerPawn.Location);
  23.  
  24.         if (distanceToPlayer < chaseDistance)
  25.         {
  26.             self.pawn.SetPhysics(PHYS_WALKING);
  27.             GotoState(\'Chase\');
  28.         }
  29.     }
  30. }
  31.  
  32. state Chase
  33. {
  34.     event Tick(float deltaTime)
  35.     {
  36.                
  37.         local Rotator DeltaRot;
  38.        
  39.         selfToPlayer =  playerPawn.Location - self.Pawn.Location; // calculate the offset between the player and the bot, in X Y Z coordinates. Direction of vector matters here.
  40.        
  41.         distanceToPlayer = VSize(selfToPlayer); // calculate the distance between the bot and the player, based on the previously calculated offset vector "selfToPlayer".
  42.                                                 // this is done by calculating the length of the offset vector.
  43.  
  44.         DeltaRot = rotator(selfToPlayer); // create a rotator that represents the rotation required to face towards the player.
  45.         DeltaRot.Pitch = 0; // remove any rotation that would cause the bot to move up into the air.
  46.  
  47.         if (distanceToPlayer < chaseDistance)
  48.         {
  49.             self.Pawn.Velocity = Normal(selfToPlayer) * self.pawn.GroundSpeed * deltaTime; // set the velocity (speed) of the bot.
  50.                                                             // velocity = normalize the offset vector "selfToPlayer" and multiply it by an arbitrary value,
  51.                                                             // which will increase the speed.
  52.  
  53.             self.Pawn.FaceRotation(RInterpTo(DeltaRot, rotator(selfToPlayer), deltaTime, 60000, true), deltaTime); // actually rotate the bot.
  54.  
  55.             self.Pawn.Move(self.Pawn.Velocity); // actually move the bot according to the velocity.
  56.         }
  57.         else
  58.         {
  59.             self.pawn.SetPhysics(PHYS_NONE);
  60.             GotoState(\'Idle\');
  61.         }
  62.     }
  63.    
  64.     event Touch(Actor Other, PrimitiveComponent OtherComp, Object.Vector HitLocation, Object.Vector HitNormal)
  65.     {
  66.        
  67.     }
  68. }
  69.  
  70. DefaultProperties
  71. {
  72.     chaseDistance = 700
  73. }
');