import direct.directbase.DirectStart from panda3d.core import * from direct.showbase.DirectObject import DirectObject from direct.task import Task #for Pandai from panda3d.ai import * class World(DirectObject): def __init__(self): base.cam.setPosHpr(0,0,55,0,-90,0) self.loadModels() self.setAI() def loadModels(self): # smiley self.smiley = loader.loadModel('smiley') self.smiley.reparentTo(render) self.smiley.setPos(0, 0, 0) # Obstacle 1 self.obstacle1 = loader.loadModel('frowney') self.obstacle1.setPos(0,0,0) self.obstacle1.reparentTo(render) # Obstacle 2 self.obstacle2 = loader.loadModel('frowney') self.obstacle2.setPos(5,0,0) self.obstacle2.reparentTo(render) def AIUpdate(self,task): self.AIworld.update() return Task.cont def setAI(self): self.AIworld = AIWorld(render) self.smileyAIchar = AICharacter("smiley",self.smiley, 100, 0.05, 5) self.AIworld.addAiChar(self.smileyAIchar) self.smileyAIbehaviors = self.smileyAIchar.getAiBehaviors() self.smileyAIbehaviors.obstacleAvoidance(1.0) taskMgr.add(self.AIUpdate,"AIUpdate") # comment both addObstacles to induce the AssertionError # comment only the last addObstacle to induce an AssertionError self.AIworld.addObstacle(self.obstacle1) self.AIworld.addObstacle(self.obstacle2) w = World() run()
I’ve struggling to get panda3d.ai working. The example works fine, but every time I try using it in a game prototype it doesnt work anymore. The above code snippet is the best narrowing down that I could do for AssertionError: !is_empty() at line 1041 of panda/src/pgraph/nodePath.cxx Commenting or uncommenting the addObstacle near the end induces the AssertionError.
Based on what is required to induce the error, my guess is that the panda3d.ai system ignores obstacles that have the exact same position as the aiChar and throws the AssertionError when the list of obstacles is empty.
Is my assumption of what’s going on correct?
All in all, if my assumption is correct, that’s easy to fix, could just put an obstacle somewhere outside of the walkable area so the list cant be empty or do a check every frame and do a small nudge so it’s off by 0.1 instead of exactly overlapping.
That assertionError is quite an abstract thing to get, took me some trial and error to figure out what it might mean. It would be nice if it could throw a more explainatory message.