Panda3D Manual: Getting StartedThe basics : Theory : The PandAI library has been built upon the design pattern of composition. There exists a main AIWorld Class which governs all updates of any AICharacters added to it. Each AICharacter has its own AIBehavior object which keeps track of all position and rotation updates based on the type of AI which is acting on that character. So in short : AIWorld -> AICharacter -> AIBehavior Each AIBehavior object has the functionality to implement all the steering behaviors and pathfinding behaviors. So once you get a reference to this object from the AICharacter, it should give you the ability to call the respective functions. Implementation : Following are the steps to get the basics of PandAI working. Don't worry if you can't understand some of them. Step 1 : To use our AI library into your game you need to import PandAI into your game code via : from panda3d.ai import * Step 2 : Create an object of the AIWorld class which defines your AI in your game world. Step 3 : Setup a task which runs continuously which keeps calling the 'Update()' function for your previously created AIWorld object Step 4 : To test this out let us also implement a simple call to the 'seek' behavior function in PandAI. To do this we need two objects: A seeker and a target. For this example, we will use Ralph (seeker) and an arrow model (target). Step 5 : Create an 'AICharacter' object and attach it to your AIWorld class (previously created). The AICharacter constructor looks for a NodePath, this can be a Model or an Actor or even an Empty NodePath. Step 6 : Get a reference to the AIBehaviors object of your previously created AICharacter class via the 'getAiBehaviors' function(). Step 7 : Call the seek function on your AIBehaviors reference (previously created). The seek function takes a NodePath or a Vector3 position to seek to. Step 8 : Start your AIWorld update task which you created earlier. Step 9 : Watch how your awesome seek function works ! The actual code : import direct.directbase.DirectStart
If you want to get a working demo of this tutorial, please visit :
Now that you have a basic working program of PandAI, you should proceed to the Steering Behaviors page and gain more knowledge of the system from there. © Carnegie Mellon University 2010 |