Announcement

Collapse

The Infinity Blade Forums Have Moved

We've launched brand new Infinity Blade forums with improved features and revamped layout. We've also included a complete archive of the previous posts. Come check out the new Infinity Blade forums.
See more
See less

[Code] Driving/Racing AI

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

    [Code] Driving/Racing AI

    hello
    iv been working on a driving/racing AI and navigation system and heres what i have so far. its very much a work in progress. i will update in a new post just to keep a record of the different stages of development.
    this first bot for example can be used as random pedestrians. delete the 'event seeplayer' to have the bot attack players when it sees them.
    heres the first bot code (updated in posts below)
    Code:
    class UTBotR extends UTBot;
    
    
    var Actor Destination;
    
    protected event ExecuteWhatToDoNext()
    {
       //Go to the roaming state
       GotoState('Roaming');
    }
    
    
    state Roaming
    {
    Begin:
       //If we just began or we have reached the Destination
       //pick a new destination - at random
       if(Destination == none || Pawn.ReachedDestination(Destination))
       {
          Destination = FindRandomDest();
       }
    
       //Find a path to the destination and move to the next node in the path
       MoveToward(FindPathToward(Destination), FindPathToward(Destination));
    
       //fire off next decision loop
       LatentWhatToDoNext();
    }
    
    event SeePlayer(Pawn SeenPlayer)
    {
    	if (Squad == None && !WorldInfo.GRI.OnSameTeam(self, SeenPlayer))
    	{
    		// maybe scripted pawn; just notify Kismet
    		GotoState('Roaming');
    	}
    	else if (UTSquadAI(Squad).SetEnemy(self, SeenPlayer))
    	{
    		// check for any Kismet scripts that might care
                    GotoState('Roaming');
    	}
    	if ( Enemy == SeenPlayer )
    	{
    		GotoState('Roaming');
    	}
    }
    
    defaultproperties
    {
    }
    the ai is in a constant state of Roaming and looks for a random path to follow.

    the navigation, make a single line of PathNodes that go all the way round your track/road making a complete circuit. try not to make sharp turns but smooth flowing direction changes, think of a 'racing line'. if the bot misses a pathnode it will stop and reverse. i have had best results placing the TeglegPathnodes as shown in this picture.
    the theory in brief is this:
    when a (vehicle) bot reaches a pathnode, it will take on its maxspeed, but because of the physics it accelerates and brakes like a car. on the straight have maxspeed on the teglegpathnode to the max. a few pathnodes before a corner (the braking zone) reduce the speed to something the bot can actually get round.
    heres a video showing the pathnodes http://www.youtube.com/watch?v=MxosndZGyEI


    select all the pathnodes, f4 to see the properties, scroll down to NavigationPoint and tick One Way Path.



    open kismet and set it up like this
    chose UTBotR as the controller class



    heres a quick video of 3 bots racing round the BenHur track from Unwheel2
    http://www.youtube.com/watch?v=mP7jjW8kru0

    i will update as and when

    things to be done:

    collision avoidance
    maybe send a trace, or event seeplayer (within a certain distance) could result in a small direction change

    please if you know of any relavent functions/ events/ variables or anything?
    any help on these matters would be greatly appreciated

    comments please
    thanks

    UPDATES
    The updated bot and pathnode you can get from a few posts below this one (there are 2 updates for the pathnode)
    Attached Files

    #2
    UPDATE

    the bot now follows special path nodes, you can set the vehicles max speed, and you can change max speed in the editor

    pathnode code:
    Code:
    class TeglegPathNode extends PathNode;
    
    var() float MaxSpeed;
    
    DefaultProperties
    {
    MaxSpeed = 100
    }
    bot code:
    Code:
    class UTBotR extends UTBot;
    
    var class<TeglegPathNode> SlowPathNode;
    
    var Actor Destination;
    
    var TeglegPathNode tpn;
    
    protected event ExecuteWhatToDoNext()
    {
       //Go to the roaming state
       GotoState('Roaming');
    }
    
    
    state Roaming
    {
    Begin:
       //If we just began or we have reached the Destination
       //pick a new destination - at random
       if(Destination == none || Pawn.ReachedDestination(Destination))
       {
          Destination = FindRandomDest();
    
       }
    
       //Find a path to the destination and move to the next node in the path
       tpn = TeglegPathNode(FindPathToward(Destination));
       MoveToward(tpn, tpn);
    
       //Set the desired speed
       SetMaxDesiredSpeed();
    
       //fire off next decision loop
       LatentWhatToDoNext();
    }
    
    event SeePlayer(Pawn SeenPlayer)
    {
    	if (Squad == None && !WorldInfo.GRI.OnSameTeam(self, SeenPlayer))
    	{
    		// maybe scripted pawn; just notify Kismet
    		GotoState('Roaming');
    	}
    	else if (UTSquadAI(Squad).SetEnemy(self, SeenPlayer))
    	{
    		// check for any Kismet scripts that might care
                    GotoState('Roaming');
    	}
    	if ( Enemy == SeenPlayer )
    	{
    		GotoState('Roaming');
    	}
    }
    
    function SetMaxDesiredSpeed()
    {
           local Vehicle V;
           V = Vehicle(Pawn);
    
           if (V != None && V.Driver != None)
    		{
                         V.AirSpeed = tpn.MaxSpeed;
                    }
    		   else
    		{
                        V.AirSpeed=2000;
                    }
    }
    
    defaultproperties
    {
    }

    Comment


      #3
      Good job, it's a nice tutorial with straight-forward code (hah! Geddit?), I have a question, will the AI break itself if your track is in a figure 8 loop? Say it crosses over a part of the track, will the AI be able to differentiate between the nav points below and above it, so it wont throw itself off the bridge to follow a path node on the ground?

      Comment


        #4
        Wow, very impressive. Thanks, for sharing.

        Comment


          #5
          Originally posted by Kyle_Katarn View Post
          I have a question, will the AI break itself if your track is in a figure 8 loop? Say it crosses over a part of the track, will the AI be able to differentiate between the nav points below and above it, so it wont throw itself off the bridge to follow a path node on the ground?
          if there is no direct line of sight to the other pathnodes it should be ok
          if it can see the other pathnodes it might try to get to them

          Comment


            #6
            TeglegPathNode Update

            TeglegPathNode Update
            bots are less likely to stop and reverse because ive increased the collision size of the teglegpathnode.
            Code:
            class TeglegPathNode extends PathNode;
            
            var() float MaxSpeed;
            
            DefaultProperties
            {
              Begin Object  Name=CollisionCylinder LegacyClassName=NavigationPoint_NavigationPointCylinderComponent_Class
            		CollisionRadius=+0500.000000
            		CollisionHeight=+0100.000000
            	End Object
            MaxSpeed = 100
            }
            if your using this system please could you gime me some feedback

            ive noticed some strange behaviour in the bot, i have an oval track they can drive round no problem at full speed, and most of the time they do just that.
            but i sometimes catch them spaking out.
            sometimes they get stuck on a wall, just seem to give up and just sit there, and 1 was going round in an endless circle backwards.

            @Kyle_Katarn
            use PathBlockingVolumes

            Comment


              #7
              nice work!

              2. some kind of speed detection or something to help in tight corners
              an idea i had was to extend the PathNode to include something like 'recomended speed'
              so you could place high and low speed pathnodes

              That is what I was doing in another engine. Each node had a minimun and maximum value and when the AI reached that node, it would increase or decrease gradually its velocity to a random value choosed between the node's value.

              Comment


                #8
                Great thread tegleg! I don't believe there has ever been a Unreal based racing game to truly have bots to race against, so this would be a first.

                Comment


                  #9
                  the basics are almost there, just a few glitches in the ai to iron out and i think you could actualy have a race
                  check the lates incarnation here
                  http://www.youtube.com/watch?v=uhsuhdNS580

                  Code:
                  [0156.15] ScriptLog: Roaming Find new path
                  [0156.15] ScriptLog: Roaming not reachable
                  [0156.15] ScriptLog: Roaming SPAAAZZZZIIINNNNNNNN
                  @unwheelmodeller
                  il send you the files soon as i get it to work half decent

                  Comment


                    #10
                    very nice UDK racing bot ai test and spazin video
                    Examples tutorial video would be very nice if you add
                    Big thanks

                    Comment


                      #11
                      Wow, great job man. Only thing I thought was odd was that your ammo went down when you bumped into something

                      Comment


                        #12
                        Please Video tutorial
                        Big Thanks

                        Comment


                          #13
                          Originally posted by UnWheelModeller View Post
                          Great thread tegleg! I don't believe there has ever been a Unreal based racing game to truly have bots to race against, so this would be a first.
                          http://unwheel.beyondunreal.com/




                          Don't know if it has bot support, but I see no reason why it shouldn't have.

                          Comment


                            #14
                            sorry bonyback
                            i cant make a tutorial vid because im still experimenting with it, im on UTBotR6 right now.
                            this is why i want people to give me some feedback, so i can improve it.
                            i want to know what you did and what the results were.
                            for example,
                            i have found putting a teglegpathnode about every 2 or 3 car lengths around corners works very well, if you follow the racing line.
                            but on straights they tend to weave around however i place them.
                            an ai 'bug' iv found is that sometimes it will randomly stop and turn round, this is because it is trying to get to a pathnode behind it. (anyone has any ideas about how to fix this please let me know)
                            tell me about your experiments with it please

                            Crusha K. Rool
                            im making it for Unwheel2

                            Comment


                              #15
                              Don't know if it has bot support, but I see no reason why it shouldn't have.
                              We were never able to get the Bot to race well in UnWheel And to make it worse, when they didn't race, they attacked any vehicle that was close.

                              tegleg's code is working almost too well:P And even when the Bots crash, they will continue to race.

                              Steven

                              Comment

                              Working...
                              X