Object doesn't collide with walls

I have set up walls in Panda3D, which I am quite new to. However, the panda doesn’t collide with them, and I am not sure why. Here is the code I think is relevant:

        wallSolid = CollisionTube(-60.0, 0, 0, 60.0, 0, 0, 1)
        wallNode = CollisionNode("wall")
        wallNode.addSolid(wallSolid)
        wall = render.attachNewNode(wallNode)
        wall.setY(50.0)
        wall.show()

        wallSolid = CollisionTube(-60.0, 0, 0, 60.0, 0, 0, 1)
        wallNode = CollisionNode("wall")
        wallNode.addSolid(wallSolid)
        wall = render.attachNewNode(wallNode)
        wall.setY(-40.0)
        wall.show()

        wallSolid = CollisionTube (0, -60.0, 0, 0,60.0, 0, 1)
        wallNode = CollisionNode("wall")
        wallNode.addSolid(wallSolid)
        wall = render.attachNewNode(wallNode)
        wall.setX(60.0)
        wall.show()

        wallSolid = CollisionTube(0,-60.0, 0, 0, 60.0, 0, 1)
        wallNode = CollisionNode("wall")
        wallNode.addSolid(wallSolid)
        wall = render.attachNewNode(wallNode)
        wall.setX(-60.0)
        wall.show()
       #This adds a collision node, so that collisions can registered
        pcColNode = CollisionNode(colliderName)
        #this assigns a sphere shaped collision box
        pcColNode.addSolid(CollisionSphere(0,0,0,6))
        self.collider = self.entityInstance.attachNewNode(pcColNode)
        self.collider.show()

        #This handles the response to collisions
        base.collisionHandler.addCollider(self.collider,self.entityInstance)
        #this handles the detection of collisions
        base.collisionDetector.addCollider(self.collider,base.collisionHandler)
        

        #this detects when collisions happen
        self.collisionDetector = CollisionTraverser()
        #this dictates how the program responds when a collision happens
        self.collisionHandler = CollisionHandlerPusher()

Capture

Ah, I think that I may see the issue: you’re creating a traverser and assigning it to a variable named “collisionDetector”, but don’t seem to be instructing that detector to traverse.

You see, Panda automatically performs traversal only for whatever traverser (if any) is assigned to the"cTrav" variable of the ShowBase class; other traversers are expected to be handled by the developer.

So, there are I believe two main solutions:

First, you could assign your traverser instead to “cTrav”; something like this:

# Presuming for simplicity that this takes place
# in a class derived from ShowBase

    self.cTrav = CollisionTraverser()

And second, you could manually call the “traverse” method on your traverser; something like this:

# Presuming for simplicity that this takes place
# in a class derived from ShowBase

# In the __init__ method (or other appropriate location)
    self.taskMgr.add(self.update, "update task")

# Elsewhere...
def update(self, task):
    self.collisionDetector.traverse(render)
    
    return task.cont

1 Like

5 posts were split to a new topic: Collisions not working