Announcement

Collapse
No announcement yet.

How Can I create a simple AI?

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

  • replied
    Ah, you were exactly right, thank you very much. For all those interested the working code is below. (though I haven't implemented the anything to make them shoot yet)

    Pawn:
    Code:
    class AttackPawn extends UTPawn placeable;
    
    
    
    
    defaultproperties
    {
    	Begin Object Name=WPawnSkeletalMeshComponent
    		bOwnerNoSee=False
    		CastShadow=true
    		bCastDynamicShadow=true
    		SkeletalMesh=SkeletalMesh'CH_IronGuard_Male.Mesh.SK_CH_IronGuard_MaleA'
    		AnimTreeTemplate=AnimTree'CH_AnimHuman_Tree.AT_CH_Human'
    		AnimSets(0)=AnimSet'CH_AnimHuman.Anims.K_AnimHuman_BaseMale'
    		bHasPhysicsAssetInstance=true
    		Scale=1.075
    	End Object
    	Mesh=WPawnSkeletalMeshComponent
    	Components.Add(WPawnSkeletalMeshComponent)
    	
    	ControllerClass=class'APAIController'
    	Physics = PHYS_Falling
    }
    Controller:
    Code:
    class APAIController extends GameAIController;
    
    
    var Pawn thePlayer; //variable to hold the target pawn
    
    simulated event PostBeginPlay()
    {
    	super.PostBeginPlay();
    	`Log("STARTUP COMPLEATE===========================================================================================");
    
    }
    
    event SeePlayer(Pawn SeenPlayer) //bot sees player
    {
    	`Log("PlayerSeen===========================================================================================");
    	
    	if (thePlayer ==none) //if we didnt already see a player
    	{
    		thePlayer = SeenPlayer; //make the pawn the target
    		GoToState('Follow'); // trigger the movement code
    	}
    }
    
    state Follow
    {
    
    Begin:
    
    	if(thePlayer != None)  // If we seen a player
    	{
    		`Log("Follow===========================================================================================");
    		MoveTo(thePlayer.Location); // Move directly to the players location
    		GoToState('Looking'); //when we get there
    	}
    
    }
    
    state Looking
    {
    Begin:
    	if(thePlayer != None)  // If we seen a player
    	{
    		`Log("Looking===========================================================================================");
    		MoveTo(thePlayer.Location); // Move directly to the players location
    		GoToState('Follow');  // when we get there
    	}
    
    }
    
    
    defaultproperties
    {
    
    }
    Of course all credit goes to tegleg because this is ripped right from his tutorial, and Xces because he helped me make it work.

    Leave a comment:


  • replied
    sounds like your pawn spawns without a physic

    just add

    Code:
    Physics = PHYS_Falling
    the the DefaultProperties

    Leave a comment:


  • replied
    Ok I went back to your tutorial code but I'm having a problem. The pawns don't react at all unless I shoot them. Based on the log I placed I can tell that they are seeing the player but for some reason they wont progress past that. Here is the code I have now.

    Code:
    class APAIController extends GameAIController;
    
    
    var Pawn thePlayer; //variable to hold the target pawn
    
    simulated event PostBeginPlay()
    {
    	super.PostBeginPlay();
    	`Log("STARTUP COMPLEATE===========================================================================================");
    
    }
    
    event SeePlayer(Pawn SeenPlayer) //bot sees player
    {
    	`Log("PlayerSeen===========================================================================================");
    	
    	if (thePlayer ==none) //if we didnt already see a player
    	{
    		thePlayer = SeenPlayer; //make the pawn the target
    		GoToState('Follow'); // trigger the movement code
    	}
    }
    
    state Follow
    {
    
    Begin:
    
    	if(thePlayer != None)  // If we seen a player
    	{
    		`Log("Follow===========================================================================================");
    		MoveTo(thePlayer.Location); // Move directly to the players location
    		GoToState('Looking'); //when we get there
    	}
    
    }
    
    state Looking
    {
    Begin:
    	if(thePlayer != None)  // If we seen a player
    	{
    		`Log("Looking===========================================================================================");
    		MoveTo(thePlayer.Location); // Move directly to the players location
    		GoToState('Follow');  // when we get there
    	}
    
    }
    
    
    defaultproperties
    {
    
    }

    Leave a comment:


  • replied
    UTBot is way more complex than it appears.
    either search the entire UTBot code for UTPawn and replace with MBPawn where appropriate, possibly generating some errors in other classes.
    or gather as many examples of ai you can find (and there are lots more besides mine) and try to learn from them and make your own.

    another possibility is to work with teams, all the bots on 1 and the player on the other.
    this involves code spread around a few classes too, theres a few functions somewhere in UTTeamGame (or similar) you need to play around with to get it to work.

    Leave a comment:


  • replied
    Ok that helped a bit, at least I understand how to connect a pawn to a controller now. I attempted to extend from UTBot Almost all of the behavior is right there. The problem is I cant keep them from attacking each other. How do I tell it to target only the player. The player is an MBPawn and the AI's are AttackPawn so they are different pawn classes and should be easy for the AI to identify. This is what I have tried so far:

    Code:
    //
    // Moon Base Game
    // Pawn
    //
    // Created by: Steven Palermo
    // Edited by: 
    //
    // Refrences:
    
    class APAIController extends UTBot;
    
    var MBPawn Target; //variable to hold the target pawn
    
    function tick(float DeltaTime)
    {
    	local MBPawn CheckPawn;
    	
    	super.tick(DeltaTime);
    	
    	`Log("===================================================================================");
    	`Log("Before: " $ Enemy);
    	
    	CheckPawn = MBPawn(Enemy);
    	if(CheckPawn != None)
    	{
    		Enemy = None;
    	}
    	
    	`Log("After: " $ Enemy);
    	`Log("===================================================================================");
    }
    
    defaultproperties
    {
    
    }
    However this code seems to have no effect. both before and after the if statement the target remains the same.

    I also tried this just to see what would happen:

    Code:
    //
    // Moon Base Game
    // Pawn
    //
    // Created by: Steven Palermo
    // Edited by: 
    //
    // Refrences:
    
    class APAIController extends UTBot;
    
    var MBPawn Target; //variable to hold the target pawn
    
    function tick(float DeltaTime)
    {
    	local MBPawn CheckPawn;
    	
    	super.tick(DeltaTime);
    	
    	`Log("===================================================================================");
    	`Log("Before: " $ Enemy);
    	
    	Enemy = None;
    	
    	`Log("After: " $ Enemy);
    	`Log("===================================================================================");
    }
    
    defaultproperties
    {
    
    }
    This does set the Enemy to none but the Attack Pawns just kill each other anyway. It would be funny really if I wasn't on a deadline, poor guys just can't get along long enough to bother killing me X D

    Leave a comment:


  • replied
    theres a few very simple ai's you can take a look at on my tutorials page

    Leave a comment:


  • started a topic How Can I create a simple AI?

    How Can I create a simple AI?

    Hey I have run into another problem and I was hoping someone could point me in the right direction. I want to create a simple AI enemy for my game. All he needs to do is wait until he sees the player then follow and attack the player until he is killed.

    Preferably I would like to use a peaceable pawn that I can drop into the level as an actor without any need to deal with kismet. From previous work I know I can create a placeable pawn by simply adding “placeable” to the class declaration at the beginning of an extended pawn script, and when the game is run the pawn will automatically default to using the controller defined in the game’s gameinfo and will run around and act normally.

    The game I am making defines MBController (my custom controller class), which extends UTPlayerController, as the default controller in its gameinfo class. By default this script apparently tells the pawn to run a deathmatch AI and it attacks any pawn it can find, I want it to only attack the player. I can tell from the logs I set up that the placeable pawns are using MBController as their controller, and I have no idea where they are getting their behavior from since I can’t find any connection to an AI controller in any of the controller parent classes.

    Thanks in advance for any help you can provide : )
Working...
X