AI Libraries for Panda3D

Progress! You guys are a great help! :smiley: Now it’s getting as far as your egg files do, which I guess means they’re fine. I’ll avoid layers and converting in the future; I note that while it didn’t accept grids flipped to -90 degrees, it did accept the ones flipped to +90 degrees. However, when the program reaches the stage “write to csv file…”, a grey panda3D screen pops up, and stays grey, with the program not progressing any further. I’ve left it alone at least 15 minutes at this stage, and observed no change; I can’t interact with it either, by pressing enter or entering input. Note that the same happens when I use final_blender_plane.egg and final_blender_plane_col.egg, the two files you included with the Zip.

I tried using the generated navmesh anyway, thinking it might already be complete (it has a size of 27kb, that seems small compared to the others), and I get about half the console’s worth of lines of “Warning: Corrupt Data!” notices, as well as a single pair of “couldnt find destrination/source” afterwards.

After that, though, the program runs, but the AI bot that follows my player-controlled character moves onto spaces that ought to be unpathable; it always runs straight behind the character, instead of avoiding walls and such. I’ve made it follow me across the whole grid, in case the orientation was somehow off by 90 or 180 degrees, but it paths over the entire grid without making any detours. The terrain is not being transformed; I also tried both deleting faces, and deleting only faces, and neither produced the expected results.

If you like, I can upload the files for you to look at. I am certain I didn’t fiddle with the BlenderMeshGen.py or anything, and all the files it had in the Zip are with it now, except the example eggs and blends and the example navmesh.

I tend to do my best problem-solving before 10:00 AM, so hopefully I’ll be enlightened tomorrow morning; that’s how it was when I was still struggling to make my characters jump into the air. A day of pulling my hair out, and the next morning it’s suddenly all so obvious. :slight_smile:

Cool so we have some progress! Ignore the gray screen that you get for the time being. The navmesh.csv file that gets created should have worked. Could you provide us your Blender files? We will try to create the navmesh.csv and test it at our end.

Thanks!

Cool, it’s great that you can take the time to have a look at this! I’ve put everything relevant to the pathfinding issues in a zip folder, which I’ve uploaded here:

uploading.com/files/b57fbbdf/Pat … erial.zip/

Recently I’ve been getting a lot of I/O Errors when uploading, so if it doesn’t work, let me know and I’ll try somewhere else.

I’ve included my test code and the relevant models (terrain and actors), in case you wanted to have a look at those; I’ve also included the navmesh that was generated, as well as both the .egg and .blend files for the full and collision meshes.

Again, thanks! I think we’re nearing the end of this. :stuck_out_tongue:

So I played around with your Blender models a bit. It all looks correct to me. Now, you said you had used Mesh->Grid to make the mesh correct? Can you instead create the mesh using a plane and subdivide?

Hit “Spacebar”
Mesh->Plane
Hit “Tab”
W->Subdivide (Each subdivide divides individual face to 4 faces. Try an 8x8 for now.)

Everything else that you did should be the same.

Let us know how it goes!

Thanks!

Hm, I tried doing it with subdivisions, and used the navmesh generated, and the NPC still ignored the navmesh. I’m off for the time being, but when I get some time again this afternoon, I’ll try using Delete Faces instead of Delete Only Faces, though you guys deleted Only Faces and it works well enough.

EDIT: I get the same when deleting Faces; the NPC follows my PC everywhere, without making any detours of any kind. Also, I get a new error on my console, “DESTINATION NOT REACHABLE MATE!”, though this might have to do with the 8x8 mesh being slightly different to the visible terrain I am clicking on.

I wonder if perhaps my code is wonky, rather than my meshes. I’ve got this in the World() class, which is the main class:

        self.aiWorld = AIWorld(render)

Then I’ve got this, when the player unit (PacUnit) and the NPC (GhostUnit) are created (called upon initialization of World()):

    def loadUnit(self, task):
        #This is the method that will create a player.
        player = PacUnit(Point3(20, 20, 2))
        follower = GhostUnit(Point3(-20, -20, 2))
        playerParent = player.giveActor()
        #ghostTarget = player.getPythonTag("unitNode")
        #followerClass = follower.getPythonTag("unitClass")
        follower.follow(playerParent)
        return task.done

This is the code I have in the NPC’s class, including the .follow() method:

        self.actorAI = AICharacter("PacManAI", self.actor, 60, 2, 20)
        world.aiWorld.addAiChar(self.actorAI)
        self.actorBehaviors = self.actorAI.getAiBehaviors()
        self.actorBehaviors.initPathFind("navmesh.csv")
        taskMgr.add(self.updateAI, "updateAIworld")

    def follow(self, target):
        self.actorBehaviors.pathFindTo(target, "addPath")
        self.actorBehaviors.pursue(target, 1.0)

    def updateAI(self, task):
        world.aiWorld.update()
        return task.cont

I wouldn’t be surprised if I’ve got a mistake somewhere in there; I’ve only been writing in Python for the past few months. I’ll let you know what happens with Delete Faces. By the time this is over, every possible error will probably have been covered. :stuck_out_tongue:

Many thanks,
Guerric
[/code]

Could you provide us the full and coll planes you used for this test? And if possible the terrain as well.

Thanks!

 def follow(self, target): 
        self.actorBehaviors.pathFindTo(target, "addPath") 
        self.actorBehaviors.pursue(target, 1.0)

pathFindTo will traverse to the target in the shortest path

pursue shouldn’t be called after it. Internally, it already does pursue to the chosen points in the pathfinder.

Also, it is wise to draw out a physical representation of your path finding coll mesh and see if you are really in the mesh or not.

I think the easiest way to solve this problem would be if you provide us a link to your files and we will fix the bug and let you know what went wrong.

Cheers.

Okay, I’ve uploaded the models. I know the spaces in the navmesh won’t line up perfectly with the walls in the terrain, but I figure there would still be pathfinding, since all PandAI needs for pathfinding is the navmesh and appropriate coordinates.

uploading.com/files/fd12fe76/Ble … Files.zip/

I hope it’s just a small detail. I will keep trying different coding variants, to see if that doesn’t help!

I’ve just watched the YouTube tuts, this project looks very cool.

I’m a Blender user.
I’ll give it a try, and report comments, crits etc…

Keep the good work up guys :slight_smile:

IMPORTANT UPDATE :

Updates to the Blender mesh generator :

  • Now creation of the full and collision meshes is to be done on the x-y plane. This makes it much easier to just get in to Blender and create a mesh since the starting view is a top view of the x-y plane.

  • We did quite a bit of testing and bug hunting and have documented some cases which might break the path finding.

  • NOTE : We advice to make meshes with a scale of 50 or above for best results. It would be wise to make your world based on this scale. Much smaller meshes bug out a bit.

  • NOTE : To make faces on your plane mesh, use the subdivide utility in Blender in Edit Mode and to delete faces option when you enter Face Selection Mode while you are in Edit Mode.

The latest Blender Mesh Generator and a simple test example of it working in python has been provided at:

srinavinnair.com/downloads

This is a much more stable version so it is advised to use it over previous versions of the Blender Mesh Generator.

Thanks for your support of PandAI.

For any further assistance, please post here.

@ GarrickW

Please remake your full and coll egg files based on the new blender mesh generator and scale your plane upto a size of 50 then subdivide and test it out.

If you look at the example which has been posted, it will give you a good head start on this.

Good Luck!

Also, just as a reminder :

In Panda 1.7.0, to use PandAI it is not libpandai any more but :

from panda3d.ai import *

Cheers.

Tried using PandaAI but it keeps crashing on me. The Terminal just says Segmentation fault or Bus error. Usually I got those when the game is hanging in some infinite loop.

Here are two error messages: pastebin.com/qnUkVTTx

Now the fish demo from a while ago works just fine but I am still posting this since I don’t see what I did wrong.

def addToAiEnv(self, ainame, model, mass, movforce, maxforce, sourceid):
		aiChar = AICharacter(ainame, model, 1.0, 1.0, 1.0) # (self, "-1", 100.0, 0.1, 30.0)
		self.aiEnv.addAiChar(aiChar)
		aiBehaviors = aiChar.getAiBehaviors()
		sourcesTargetID = self.ShipObjects[sourceid].selectedTargetID
		aiBehaviors.pursue(self.ShipObjects[sourcesTargetID].ShipModel, 1.0)

And I am just running it as a task

def updateAiEnv(self, task):
		self.aiEnv.update()
		return task.cont

@ Bradmante

I would suggest the best way to test out PandAI related bugs is to first create a simple program which uses the ai. So in this case a simple model pursuing another model.

If this works, then there is an error in the game code rather than the AI code. I can provide a simple sample of this if so required. Though I think it is pretty trivial from the documentation.

On another note,

I looked at the stack trace you gave me and from the code you have posted it is hard to debug what the error could be. Is it possible that it is trying to pursue a null object or that the object gets destroyed and the ai is still trying to pursue it ?

Well, if you got a sample program ready, please post it. Though as I said the fishing sample works. What I am doing is quite simple. Just pursue another node. That node is another space ship and it’s alive and well. I’d like to point out that my project has reached a certain stage of complexity and that it is specifically the libpandaai.dylib crashing. I am propably the first OS X user using PandaAI. Quite often I’m thinking that about features.

Is there documentation in the manual? I mean the node path that is being followed doesnt have to be part of the PandaAI char list, right?

Sure. I will make one in python and post it as soon as possible.

In the mean time, could you post a version of your crashed game with as much of the complexity/art removed so I can analyze the crash. Specifically if you can isolate the pursue from the rest of your code.

I personally am not too familiar with OSX and I really hope that it is not an OS issue.

The only documentation right now is on the download page :

etc.cmu.edu/projects/pandai/Download.html

which I guess you might have already seen.

Well extracting the code will take forever, but maybe I’ll do it.
I also noticed that the AI update() thread runs fine as long as there are no characters added.

The fish demo works, but it looks like the AI classes are instanced differently, more directly. I also tested the other 1.0 demos. The .dylib always crashes as soon as path finding starts. Now you can blame that on .csv errors, I had those before with different demos from people.

Static Obstacle Demo

error opening navmesh.csv file!
Bus error

Dynamic Obstacle Demo

error opening navmesh.csv file!
error opening navmesh.csv file!
error opening navmesh.csv file!
error opening navmesh.csv file!
couldnt find source
couldnt find destination
Bus error

Path finding Ralph

error opening navmesh.csv file!
Segmentation fault

So correct me if I am mistaken but is there an inherent problem with csv and OSX ? Because those demos have tested before and they have worked on all the tests. Ofcourse, none were OSX tests though. Sorry about that.

The other errors would be consequences of that.

Well I just tried that and … no. I had to extract and rewrite too much … Position loop, target selection, spawn targets, player movement, fire functions etc.

The fish / hook game works. So what’s different there? As I said, I think things are instanced differently, but …

And again: does the character/node that is being followed have to be part of pandaai itself? Or can it just be a node?

EDIT:

rdb pointed me in the right direction. The whole navmesh.csv stuff works if I cd in the directory of the demo first. Then the dynamic and static demos suddenly work.

So what am I doing wrong? Usually I got Bus errors and that when I was using task incorrectly that are executed every frame.