Announcement

Collapse
No announcement yet.

simple ai that follows the player?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    simple ai that follows the player?

    I managed to create and spawn my own ai using http://wiki.beyondunreal.com/wiki/Spawning_Your_Own_Bot but instead of him doing nothing I really want him to follow the player.. Does anyone have any idea on how to go about doing that?

    Thank you very much..

    this is for unreal 2004..

    #2
    theres already a comand for that.

    Look into making your own controller, and try something like moveToPlayer, i remember watching a matinee vtm where they used that command, and the bot would just chase the player around forever.

    Comment


      #3
      Yeah thats basically it. The only other thing you might need is an Action_GoTo and have it keep going back to 'move to player' Because when the pawn reaches the player that would be the end of the script and he wouldn't move anymore. If you set the GoTo to make it refer back to the step with the movetoplayer command, he'll always be trying to move to player, even after he catches them once.

      Comment


        #4
        Mmm...

        Ok, but this don't give you any ideas on how to make it work.
        So... i will explain you how to.

        Well, to make a bot, following a player you have to:

        1)Create a subclass of AIController to control the Bot's pawn;
        2)Create a subclass of xPawn wich is the Bot's Controller's Pawn;

        1)Example:

        Code:
        Class myBotController Extends AIController;
        
        Defaultproperties
        {
                 PawnClass=Class'myBotPawn'
        }
        2)Example:

        Code:
        Class myBotPawn Extends xPawn;
        
        DefaultProperties
        {
                 ControllerClass=Class'myBotController'
        }
        This way you directly link the controller class to the pawn class, so when you call Level.Game.RestartPlayer(myBotController);
        The pawn you need is automatically spawned.

        The code to follow the player

        The code you need to follow a player is not as simple as you can figure out, because if you can see the player, then it doesn't mean you can reach it by just executing something lik MoveToward(Player,....);

        Well, here's an example of what you need:

        Code:
        Class myBotController Extends AIController;
        
        var() PlayerController myPlayer;
        var() Pawn myPlayerPawn;
        
        Function Restart()
        {
               Super.Restart();
               GotoState('SearchPlayer');
        }
        
        State SearchPlayer
        {
            function BeginState()
           {
                  myPLayer = None;
                  myPlayerPawn = None;
        
                 SetTimer(1.0, False); // 1.0 is the search rate.
           }
        
           Function TImer()
           {
                  Local PlayerController aPlayer, BestPlayer;
                  Local Pawn aPawn, BestPawn;
        
                 Local Float Dist, BestDist;
        
                 ForEach AllActors(Class'PlayerController', aPlayer)
                {
                      if ( aPlayer.bOnlySpectating )
                          Continue; //We don't want spectators.
                      
                      aPawn = aPLayer.Pawn;
                      if ( sPawn == None )
                           Continue;
        
                      if ( CanSee(aPawn) )
                     {
                           Dist = vSize(aPawn.Location - Pawn.Location)-Pawn.CollisionRadius - aPawn.CollisionRadius; //Calculate distance
                          if ( Dist < BestDist || BestPawn == None )
                         {
                              BestPawn = aPawn;
                              BestPlayer = aPlayer;
                              BestDist = Dist;
                         }
                     }
        
                     myPlayer = BestPlayer;
                     myPlayerPawn = BestPawn;
                     if ( myPlayer != None && myPlayerPawn != None )
                          GotoState('FollowPlayer');
                     else
                           SetTimer(1.0, False);
                }
           }
        
        }
        
        State FollowPlayer
        {
        
              Function Tick(Float Dt)
              {
                     if ( MyPlayer == None || myPLayerPawn == None
                          || MyPlayerpawn.Health <= 0 )
                         GotoState('SearchPlayer'); //Whenever the player dies search again for a player.
        
                     if ( LineOfSightTo(myPlayerPawn) )
                         Focus = Enemy;
                     else
                        Focus = MoveTarget;
               }
        
               Function EndState()
               {
                     myPlayer = None;
                     myPLayerPawn = None;
               }
        
        Begin:
        if ( vSize(MyPlayerPawn.Location - Pawn.Loation)-Pawn.CollisionRadius-MyPlayerPawn.CollisionRadius < MinDist ) //If we reached the minimal distance to that player, stop (mindist have to be defined.
        {
            Pawn.Acceleration = vect(0,0,0);//Stop
           //Put Here middle-check code.
           Sleep(0.5); //Reaction TIme
           Goto('Begin'); //Recheck if we must move.
        }
        
        //Else follow him
        Follow:
        MoveTarget = FindPathToward(myPlayerPawn);
        if ( MoveTarget != None )
        {
            Pawn.ShouldCrouch(False); //Decide here if pawn should crouch or not.
            Pawnl.SetWalking(False); //Here if he should walk or not.
            MoveToward(MoveTarget, Focus,,(Focus != myPlayerPawn),Pawn.bIsWalking);//The function doesn't return until movetarget have been reached.
            //Whe moved to moveTarget. put here any other code. warning: movetarget may not be myPlayerPawn!
        }
        Sleep(0.5); //Reaction Time
        Goto('Begin'); //Recheck
        
        }

        Comment


          #5
          Might also wanna try looking through the code for Rainbow Six (the newest one). They probably have some code in there that does what you're looking for.

          Comment


            #6
            This function is in SquadAI.

            function bool TellBotToFollow(Bot B, Controller C)

            You may be able to just tell the bot.setRouteGoal(Player) where player is the human pawn you want to follow.

            Comment


              #7
              Ahh the momories of my sweet sweet Cujo!
              Here Cujo, here boy!

              Where did Cujo originate? I had the Cujo bot for Quake 1.

              Comment

              Working...
              X