Results 1 to 13 of 13

Thread: Help with AI ..

  1. #1

    Default Help with AI ..

    I'm a beginner in UnrealScripting. we are using UDK to make a game for our project and so far everything else is done, the only thing that is left is AI.. after going through some online tutorials and I created a simple AI that when sees the player , moves up to the player and when the AI has reached certain amount of distance it shoots at the player.

    I did this based on a tutorial... and this is how I did it. i made a class MyAIController extends AIController; and then made a class Myenemy that extends from UDK pawn and i have made this as a placeable actor (is this a good practice ?)

    So far I got the AI to follow me when ever it spots me, how ever it doesn't shoot me when it gets close and for when i shoot it.. it doesnt die.. its like the pawn is immune to the shots.. i can't even see the weapon i have given it.. but if i shoot it for a while it will drop the weapon and will stop moving o_O !.

    these are my questions.. i decided to post them in a single thread instead of multiple ones..
    1. What am i doing wrong in the first bit (code posted at the end)
    2.is it possible to make the AI characters perform an animation before going to the chase state (i want them to do the throat slit anim )
    if so how do i do that ? i can't seem to get my head around it
    3. right now my pawns are placeable actors.. is this a good way to spawn them ? or should i use kismet ? if so how do i spawn multiple enemies at the same time ? and how do i make sure that kismet doesn't spawn a new one when i killed them all ?

    Any help would be appreciated ! .


    AIcontroller Code
    Code:
    class MyAIController extends AIController;
    
    
    var Actor target;
    var() Vector TempDest;
    
    event Possess(Pawn inPawn, bool bVehicleTransition)
    {
        super.Possess(inPawn, bVehicleTransition);
        Pawn.SetMovementPhysics();
    }
    simulated event GetPlayerViewPoint(out vector out_Location, out Rotator out_Rotation)
    {
        // AI does things from the Pawn
        if (Pawn != None)
        {
            out_Location = Pawn.Location;
            out_Rotation = Rotation; //That's what we've changed
        }
        else
        {
            Super.GetPlayerViewPoint(out_Location, out_Rotation);
        }
    }
    //I'm adding an default idle state so the Pawn doesn't try to follow a player that doesn' exist yet.
    auto state Idle
    {
        event SeePlayer (Pawn Seen)
        {
            super.SeePlayer(Seen);
            target = Seen;
            GotoState('Follow');
        }
    Begin:
    }
    
    state Follow
    {
        ignores SeePlayer;
        function bool FindNavMeshPath()
        {
            // Clear cache and constraints (ignore recycling for the moment)
            NavigationHandle.PathConstraintList = none;
            NavigationHandle.PathGoalList = none;
    
            // Create constraints
            class'NavMeshPath_Toward'.static.TowardGoal( NavigationHandle,target );
            class'NavMeshGoal_At'.static.AtActor( NavigationHandle, target,32 );
    
            // Find path
            return NavigationHandle.FindPath();
        }
    Begin:
    
        if( NavigationHandle.ActorReachable( target) )
        {
            //FlushPersistentDebugLines();
            //Direct move
            MoveToward( target,target );
        }
        else if( FindNavMeshPath() )
        {
            NavigationHandle.SetFinalDestination(target.Location);
           FlushPersistentDebugLines();
            NavigationHandle.DrawPathCache(,TRUE);
            
            // move to the first node on the path
            if( NavigationHandle.GetNextMoveLocation( TempDest, Pawn.GetCollisionRadius()) )
            {
                //DrawDebugLine(Pawn.Location,TempDest,255,0,0,true);
                //DrawDebugSphere(TempDest,16,20,255,0,0,true);
                MoveTo( TempDest, target );
            }
        }
        else
        {
            //We can't follow, so get the hell out of this state, otherwise we'll enter an infinite loop.
            GotoState('Idle');
        }
       	if (VSize(Pawn.Location - target.Location) <= 256)
    	{
    		GotoState('Shoot'); //Start shooting when close enough to the player.
    	}
    	else
    	{
    		 goto 'Begin';
    	}
    
    
    }
    state Shoot
    {
        function Aim()
        {
            local Rotator final_rot;
    
            final_rot = Rotator(vect(0,0,1)); //Look straight up
            Pawn.SetViewRotation(final_rot);
        }
    Begin:
        Pawn.ZeroMovementVariables();
        Sleep(1); //Give the pawn the time to stop.
        Aim();
        Pawn.StartFire(1);
        Pawn.StopFire(1);
        GotoState('Idle');
    }
    
    
    DefaultProperties
    {
    }
    MyEnemy Code
    Code:
    class MyEnemy extends UDKPawn;
    
    
    
    event PostBeginPlay()
    {
        super.PostBeginPlay();
        //AddDefaultInventory(); //GameInfo calls it only for players, so we have to do it ourselves for AI.
    }
    
    DefaultProperties
    {
        Begin Object Name=CollisionCylinder
    		CollisionHeight=+44.000000
        end object
        Begin Object class=SkeletalMeshComponent Name=SandboxPawnSkeletalMesh
     	SkeletalMesh=SkeletalMesh'CH_IronGuard_Male.Mesh.SK_CH_IronGuard_MaleA'
    	AnimSets(0)=AnimSet'CH_AnimHuman.Anims.K_AnimHuman_BaseMale' 
    	AnimTreeTemplate= AnimTree'CH_AnimHuman_Tree.AT_CH_Human'
    	HiddenGame=FALSE 
    	HiddenEditor=FALSE
        End Object
        Mesh=SandboxPawnSkeletalMesh
        Components.Add(SandboxPawnSkeletalMesh)
        ControllerClass=class'Mygame.MyAIController'
        InventoryManagerClass=class'Mygame.SandboxInventoryManager'
        bJumpCapable=true
        bCanJump=true
        GroundSpeed=200.0 //Making the bot slower than the player
    }

  2. #2
    Banned
    Join Date
    Feb 2011
    Location
    BXL/Paris
    Posts
    2,169

    Default

    First of all, this code is very basic and can be base for something more advanced. For now there is no AI behavior implementation... You can make this work, but this is hopeless...

  3. #3

    Default

    Quote Originally Posted by VendorX View Post
    First of all, this code is very basic and can be base for something more advanced. For now there is no AI behavior implementation... You can make this work, but this is hopeless...
    Yikes ! . thats not good at all ! .. , any advice on what to do next ? .. cos this is a dead end for me !!

  4. #4
    Banned
    Join Date
    Feb 2011
    Location
    BXL/Paris
    Posts
    2,169

    Default

    1. Extend from AIController is not good, it missing many functionality - which you need and most of it is executed natively. You can use to write some basic AI like turrets...
    2. If you know what to do, you can extend from UDKBot - but still you need implement AI behavior.
    3. UTBot have all already implemented - but it depend on UT family (GameInfo, PC, AI, Weapons etc. - all must came from UT).

    Make your choice...

    Personally, UT family is easy to modify - you don't need start from scratch. For example, look at UT3 - there is many mods or total conversions, which are made only by modify base classes.
    Of course, here in UDK section everyone try to extend from UDK (even those, who know nothing about scripting...) and write his own code and will told you to do the same.

    BTW. There is many treads talking about AI, even you can find complete source code - find it and adp what your need.
    Last edited by VendorX; 02-26-2012 at 07:33 PM.

  5. #5

    Default

    Quote Originally Posted by VendorX View Post
    1. Extend from AIController is not good, it missing many functionality - which you need and most of it is executed natively. You can use to write some basic AI like turrets...
    2. If you know what to do, you can extend from UDKBot - but still you need implement AI behavior.
    3. UTBot have all already implemented - but it depend on UT family (GameInfo, PC, AI, Weapons etc. - all must came from UT).

    Make your choice...

    Personally, UT family is easy to modify - you don't need start from scratch. For example, look at UT3 - there is many mods or total conversions, which are made only by modify base classes.
    Of course, here in UDK section everyone try to extend from UDK (even those, who know nothing about scripting...) and write his own code and will told you to do the same.

    BTW. There is many treads talking about AI, even you can find complete source code - find it and adp what your need.

    I extended my game n UDKGame.. but can i extend my AI from UTBots ? .. or is that not possible because I extended mine off from UDKGame

  6. #6
    Banned
    Join Date
    Feb 2011
    Location
    BXL/Paris
    Posts
    2,169

    Default

    You can't do this - read point 3.

    ...but what you can is, extend from UDKBot and look in to UTBot how AI behavior is implemented - learn from others is the best way to understand Uscript.
    Last edited by VendorX; 02-26-2012 at 08:25 PM.

  7. #7
    Skaarj
    Join Date
    Feb 2012
    Location
    Ottawa, Canada
    Posts
    19

    Default

    I personally haven't dealt with AI, but I find VendorX's attitude when dealing with you disgusting. There's absolutely no encouragement there, no desire to help you in the direction you're going, and instead forcing you to believe that what you want to do is outside of the scope of your abilities.

    That said, yeah - it's difficult to extend from the more basic classes in UDK, but not all of us want to produce a UnrealTournament clone or mod. Some of us want to venture further. And there are at least a handful of tutorials that can help us. Something I think that may be of use to you (since it deals with extending from AIController) is http://www.moug-portfolio.info/index.php?page=ai-pawns . If that particular article doesn't help, browse through the other ones there. I've found that site to be quite helpful.

    One thing of use VendorX did mention - or at least, I think this is what he meant - is that a good way to learn is by looking at others' code. If you haven't already, grab UnCodeX, a program that lets you view the UDK engine code in a highly organized environment. You can follow how things are extended and from that better understand how you should go about writing your own code. For example, you might look at the UTBot code and use it as reference while writing your own class.

    Just because most people extend from higher level classes doesn't mean that you have to. It's absurd that anyone would even suggest that.

    Oh, one more thing - if you do happen to figure out how to do what you're doing, be sure to put it out there. Even if you're essentially repeating something someone else has already stated in your own words, please do it. We really are lacking tutorials, articles and reference material for those looking to extend from UDK's more basic classes. It sounds to me like you're undertaking an interesting project, so if you haven't yet, consider starting a blog or something like that. If you do, let me know!
    Last edited by Uncomfortable; 02-27-2012 at 01:50 AM.

  8. #8

    Default

    AI is a timeconsuming thing to develop, at least to develop well.

    But if you don't want a typical and simple arena bot AI, it pretty much has to be done.
    I'm making a game!

    http://www.desura.com/games/modulated
    Click the link above to read more!

  9. #9
    Banned
    Join Date
    Feb 2011
    Location
    BXL/Paris
    Posts
    2,169

    Default

    Quote Originally Posted by Uncomfortable View Post
    I personally haven't dealt with AI, but I find VendorX's attitude when dealing with you disgusting. There's absolutely no encouragement there, no desire to help you in the direction you're going, and instead forcing you to believe that what you want to do is outside of the scope of your abilities.

    That said, yeah - it's difficult to extend from the more basic classes in UDK, but not all of us want to produce a UnrealTournament clone or mod. Some of us want to venture further. And there are at least a handful of tutorials that can help us. Something I think that may be of use to you (since it deals with extending from AIController) is http://www.moug-portfolio.info/index.php?page=ai-pawns . If that particular article doesn't help, browse through the other ones there. I've found that site to be quite helpful.

    One thing of use VendorX did mention - or at least, I think this is what he meant - is that a good way to learn is by looking at others' code. If you haven't already, grab UnCodeX, a program that lets you view the UDK engine code in a highly organized environment. You can follow how things are extended and from that better understand how you should go about writing your own code. For example, you might look at the UTBot code and use it as reference while writing your own class.

    Just because most people extend from higher level classes doesn't mean that you have to. It's absurd that anyone would even suggest that.

    Oh, one more thing - if you do happen to figure out how to do what you're doing, be sure to put it out there. Even if you're essentially repeating something someone else has already stated in your own words, please do it. We really are lacking tutorials, articles and reference material for those looking to extend from UDK's more basic classes. It sounds to me like you're undertaking an interesting project, so if you haven't yet, consider starting a blog or something like that. If you do, let me know!
    You're hopeless... Read more carefully others posts, then you can tell your opinion, because that what you said is nothing new. Even your link... Look closer at his code and compare with this from your link - something similar?

  10. #10

    Default

    Quote Originally Posted by Uncomfortable View Post
    Something I think that may be of use to you (since it deals with extending from AIController) is http://www.moug-portfolio.info/index.php?page=ai-pawns . If that particular article doesn't help, browse through the other ones there. I've found that site to be quite helpful.
    my code is using his example , What I'm trying to do do is make the AIPawn move and shoot properly , i might have derped up the shooting function. I'm not really looking to implement super duper behaviour, his code makes the AI move towards the player and shoot when at a certain distance.. which is all i want for the game i'm making !.. but the problem here is

    I can't kill the AI ., shooting him for a while makes him drop his weapon , but his body stays still. i think i'm missing an event take damage function for the AI ? and if i can fix him shooting at me. i'll be happy.. if all else fails i'll just use the UTbots !! >.<

  11. #11
    Banned
    Join Date
    Feb 2011
    Location
    BXL/Paris
    Posts
    2,169

    Default

    Quote Originally Posted by cyberbemon View Post
    I'm not really looking to implement super duper behavior...
    OK then, here is your stupid Bot:

    Quote Originally Posted by cyberbemon View Post
    if i can fix him shooting at me. i'll be happy...
    SandboxAIController work just fine, look at your weapon code (if your Bot have any...).

    Quote Originally Posted by cyberbemon View Post
    shooting him for a while makes him drop his weapon , but his body stays still...
    That you need implement in State Dying.

    BTW. Add some DynamicLightEnvironment in Pawn and bIsPlayer=True in def prop of SandboxAIController.
    Last edited by VendorX; 02-27-2012 at 11:29 AM.

  12. #12

    Default

    ohk the bot shoots at me now.. for some reason the weapon isn't showing up !.. but I don't care about that.

    about the State Death.. i'm kinda stuck at that.. so i added


    Code:
    event TakeDamage(int DamageAmount, Controller EventInstigator, Vector HitLocation , Vector Momentum, 
    Class<DamageType> DamageType, optional TraceHitInfo HitInfo, optional Actor DamageCauser)
    {   
    	
    	Destroy();
    		
    }
    is there any way I can play an animation before destroy() ?

  13. #13
    Banned
    Join Date
    Feb 2011
    Location
    BXL/Paris
    Posts
    2,169

    Default

    Look in to UTPawn - same state...


 

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Copyright ©2009-2011 Epic Games, Inc. All Rights Reserved.
Digital Point modules: Sphinx-based search vBulletin skin by CompletevB.com.