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

[WIP] UDK Behavior Tree Kit

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

    [WIP] UDK Behavior Tree Kit

    I have started working on a Behavior Tree Kit for UDK. Here is the link to the assembla site, right now it's svn download only because it's not in a releasable state yet. If your interested with it and want to play around with it feel free.

    http://www.assembla.com/spaces/udk-b...qr4BPXacwqjQXA

    It does not try to replace the built in state system but is an attempt to work well with it and make it easier to describe and have more complex decision making. The states are used in the Base Class to manage the initialization and running of the tree, and as well for latent functions such as MoveToward.

    It's bare bones right now but functions and includes some conditions and functions as well as how to have the tree call a latent function ( a basic moveto ). There is no editor or parser for the tree descriptions other than some helper macros. The Tree for a particular AI is described as a series of functions right now. The idea is you extend the BaseClass and then override the notinitialized state with a new tree description. Here's an example.

    Code:
    auto state notinitialized
    {
    
        function bool BuildTree()
        {
            local Array<BTKValue> TempArgs;
            local BTKValue param0;
            //`Entry
            
            //Tree Root, Sequence Node_001
            Root = BuildComposite(BTKC_SEQUENCE);
            CurrentBuilderParent = Root;
                //Node_001_1stChild_Condition - SeePlayer
                CurrentBuilderNode = BuildLeaf(BTKL_CONDITION);
                BTKConditionalNode(CurrentBuilderNode).ConditionDelegate = BTSeePlayer;
                CurrentBuilderParent.AddChidNode(CurrentBuilderNode);
    
                //Node_001_2ndChild_Action - Print message
                CurrentBuilderNode = BuildLeaf(BTKL_ACTION);
                param0.Type = BTKS_STRING;
                param0.s = "I see you Mister Player Man!";
                TempArgs.AddItem(param0);
                BTKActionNode(CurrentBuilderNode).MyArgs = TempArgs;
                BTKActionNode(CurrentBuilderNode).ActionDelegate = PrintClientMessage;
                CurrentBuilderParent.AddChidNode(CurrentBuilderNode);
                TempArgs.Remove(0,TempArgs.Length);
    
                //Node_001_3rdChild_Condition - BTActorReachable
                CurrentBuilderNode = BuildLeaf(BTKL_CONDITION);
                BTKConditionalNode(CurrentBuilderNode).ConditionDelegate = BTActorReachable;
                CurrentBuilderParent.AddChidNode(CurrentBuilderNode);
                
                //Node_001_4thChild_Action - Print message
                CurrentBuilderNode = BuildLeaf(BTKL_LATENT_ACTION);
                BTKLatentActionNode(CurrentBuilderNode).Initialize('movetowardstate',self);
                CurrentBuilderParent.AddChidNode(CurrentBuilderNode);
    
    
            //`Exit
            return true;
        }
        
        Begin:
            `Log("BTKController Ready for initialization"@self);
            if(BuildTree())
            {
                bInitialized = true;
                //gotostate('readytree');
                gotostate('testtree');
            }
            else
            {
                gotostate('hibernate');
            }
    }
    New conditions and actions fit a delegate pattern and are added in the file as well.

    #2
    If I understand this right...could the AI modify its own tree to change its behavior on the fly? Sort of like an adaptive AI?

    Very interesting though. I will keep it bookmarked

    Comment


      #3
      Yes.

      I have thought about using it to have AI LOD's for example. It's just a matter of re-initializing the tree with the new pattern.

      Comment


        #4
        Great Stuff, if that's what i'm thinking then that's an interesting thing

        Comment


          #5
          Update 3-17-2013 xml file support

          Added support for XML definition of behavior trees by integrating the udk-xml-library found at https://code.google.com/p/udk-xml-library/.

          The xml below is included in the kit as a working example with a bot who will do this. A simple experiment it would be just to change the Param0 text for the Bot to print something different as he chases you.

          The kit is not a complete API, but a starting point. New Actions and Conditions are called from their name in the xml, from Arrays that match their name to the corresponding delegate function.

          I'm not sure the next step I will add to this. It would probably be more useful to add a larger library of Behaviors, such as find cover, get weapon pickups, etc. But, I've also thought of integrating a Visual BT editor or extending something like Inkscape to create the xml files.

          Code:
          <root>
              <behavior type='Sequence' name='Root Sequence' numParams='0'>
           		<behavior type='Condition' name='See Player' numParams='0'>
          		</behavior>
          		<behavior type='Action' name='Print Message' numParams='1' ParamType='string' Param0='I can catch you!'>
          		</behavior>
          		<behavior type='Condition' name='Player is reachable' numParams='0'>
          		</behavior>
          		<behavior type='Action' name='Move Toward Player' numParams='0'>
          		</behavior>
              </behavior>
          </root>

          Comment

          Working...
          X