Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Edit 2 : Updated code, so runnable zip isn't the same as the copied section bellow (though all that has changed is that part in run_me.py)

Edit: Runnable zip with source files, sorry: https://dl.dropboxusercontent.com/u/12781104/Collisions.zip

Right now I am trying to create a small room for my character to walk around in, it works decently but will walk through walls, I am having difficulty setting up the collision logic to stop the character from walking through walls. The problem is properly creating the collision plane to line up with the walls (is there a way to do this in blender?)...

Code so far that has to do with wall collisions

 [Removed imports]

    ....

    self.cTrav = CollisionTraverser()
    robotCHandler = CollisionHandlerQueue()
    robotWallCHandler = CollisionHandlerPusher()

    WALL_MASK=BitMask32.bit(2)


    ralphStartPos = (0, 0, 0)
    self.ralph = loader.loadModel("robot.x")
    self.ralph.reparentTo(render)
    self.ralph.setScale(1)
    self.ralph.setPos(ralphStartPos)
    self.ralph.setCollideMask(BitMask32.allOff())
    # setup tube to suround robot
    #(robot is 3 height, by 1.5, 1.5)
    cTube = CollisionSphere(0, 0, 0, 3)


    robotCollisionNode = self.ralph.attachNewNode(CollisionNode('robotcnode'))
    robotCollisionNode.node().addSolid(cTube)
    robotCollisionNode.node().setFromCollideMask(WALL_MASK)
    robotCollisionNode.node().setIntoCollideMask(BitMask32.allOff())




    self.environ = loader.loadModel("room2.x")
    self.environ.reparentTo(render)

    root = self.environ.find("**/Root")
    walls = root.findAllMatches("**/Plane*")

    for w in walls:
        # set it to the same bitmask so the collider collides
        w.node().setIntoCollideMask(WALL_MASK)

    robotWallCHandler.addCollider(robotCollisionNode, self.ralph)

    self.cTrav.addCollider(robotCollisionNode, robotWallCHandler)

The bottom line is what I am most confused about, how do I get the collision plane properly setup, do I just have to hard code the points or is there something easier (maybe the geom nodes?)?

share|improve this question

1 Answer 1

up vote 1 down vote accepted
+50

You should be able to export the collision data from Blender without any setup necessary in Panda3D (no setIntoCollideMask). Go to the Logic panel, then add a String property called "Collide" set to "Polyset keep descend". Do this for all your wall objects that you want to be collideable, and it will work out of the box.

If you would like to keep your collision geometry separate from the visible geometry, you can do that too, you'll just need to set the property to "Polyset descend" to tell Panda that that mesh is only to be used as collision geometry and not as visible geometry.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.