[RESOLVED] CollisionHandlerFloor Questions

Hey, I have a few questions about how I’m handling the collisions with the floor. Here is my relevant code:

collisionRay = CollisionRay()
        collisionRay.setDirection(0, 0, -1)
        collisionNode = CollisionNode("agentRay")
        collisionNodePath = self.attachNewNode(collisionNode)
##        collisionNodePath.show()
        base.floor.addCollider(collisionNodePath, self)
        base.cTrav.addCollider(collisionNodePath, base.floor)

Allow me to explain a bit. This code is inside a class that inherits from NodePath. It’s basically an actor with move forward/backward and turn left/right methods. The nodePath looks something like this:

CollisionNodePath(“agentSphere”) # used for wall collisions
CollisionNodePath(“agentRay”) # used for floor collisions[/list:u][/list:u]

I did it this way so I could implement physics effects using an ActorNode. Those are currently disabled at the moment so I can focus on basic collision handling.

Right now I create a new Agent (my custom class), and setZ(10) so that he’ll fall on the floor. But instead, he falls right through the floor into infinite. What could cause this?

I’m already calling base.cTrav.setRespectPrevTransform(True). I’m not sure what base.floor is used for. Any ideas?

Thanks in advance.

I don’t see anything obviously wrong in the snippet you pasted.

There’s no such thing as base.floor by default, so if you have a base.floor, it must be something that you have created. From the code you pasted, it must be a CollisionHandler of some kind, presumably a CollisionHandlerFloor. (Note that a CollisionHandlerFloor won’t normally drop your object to infinity; if the object is not over a floor, it won’t move it at all.)


Thank you for the quick reply. I noticed base.floor in one of the code snippets I found on the internet. I wasn’t sure if anything special was done with it like base.cTrav.

So base.floor doesn’t necessarily need to be defined. I could use my own CollisionHandlerFloor with the same effect.

Presuming that I have the panda3d physics engine disabled, the CollisionHandlerFloor will make my character drop if he’s over a floor?

If so, will the built-in physics engine interfere with this property?

It certainly does if you’re referencing it, as in the above snippet. If you’re not getting an error, and you haven’t defined base.floor somewhere else, are you sure you’re actually running that code?

Yep. You’ll need a completely different system if you plan to use the physics engine. The CollisionHandlerFloor is only for non-physics based simulations. I think you’d probably want to use a PhysicsCollisionHandler instead, and you would attach this to your sphere, not to any ray. You wouldn’t use a ray at all in a physics-based simulation.


Sorry, I forgot to mention this. The function where this is called takes in a collisionTraverser as an argument. I use that in my real code instead of base.cTrav. In a similar way, my CollisionHandlerFloor in my real code is defined right above where I use it:

floor = CollisionHandlerFloor()
floor.addCollider(collisionNodePath, self)
collisionTraverser.addCollider(collisionNodePath, floor)

If I can safely ignore base.floor I’ll just keep the above code the way it is if we decide not to implement physics, which leads me to my next question:

Okay, but what if I use rays as rangefinder sensors in another area of code? As long as they are independent from the physics CollisionNodes via into/from masks, I should be okay, right?

Sure, that’s fine. I just meant that the rays wouldn’t be directly involved in the physics.


Awesome, thanks for the quick reply. I can’t wait to get home and try it!

It works exactly as promised. Thanks for your help!

joem86, if you just need to make a walk-run-jump avatar game, there is a much simpler solution that is the neat GravityWalker module that will take care of all the physics hassle. If you wanna diggin into, download here the sample.zip package (in the first post of the thread) and you’ll find, besides other useful samples, the gravitywalker one in the camera folder with also .blend sources to see and learn how to build your scene properly.