Collision Detection for a Cube and Uneven Ground?

Hello, I am newly starting Panda3D again, and I’m working on my old project. I am trying to make it so that a cube can move on uneven ground, but it won’t work. Here is my code that I got from the documentation on this website:

self.model = loader.loadModel('greencube.egg')
self.model.reparentTo(terrain)

fromObject = self.model.attachNewNode(CollisionNode('colNode'))
fromObject.node().addSolid(CollisionRay(0, 0, 0, 0, 0, -1))

lifter = CollisionHandlerFloor()
lifter.addCollider(fromObject, self.model)

I have more, just the rest isn’t the collision detection. What happens is the cube moves through the ground like it’s not even there. Here is a screenshot to show what I mean:

How could I change the code to make the cube move with the ground?

Does your terrain have collision geometry?

No, How would I put that in? I didn’t see where it explained to do that.

From where are you getting your terrain model?

If you’re importing from Blender using Yabee, then it may depend on which version of Blender you’re using: the version of Yabee that works with Blender 2.62 doesn’t include the relevant functionality, leaving you adding the relevant tags yourself to the egg file. If, however, you have Blender 2.63a or later, it seems that you should be able to simply specify the relevant tags in Blender and have them exported by Yabee.

So, what are you using?

I’m using Blender 2.61. Should I upgrade to a higher version?

It might make things easier, yes.

(I’m not entirely sure of the following, having not done it myself for a while, but think that I’m correct; if it doesn’t work, then try looking through or asking in the Yabee thread.)

If you do, then get the latest version of Yabee and try selecting your terrain object, adding a custom property named “Collide” and giving it the value “Polyset keep descend”; then try exporting again.

That done, open your new egg file in pview and press “shift-c”; you should see collision geometry overlaying your standard geometry.

I did what you said, and when I hit shift-c in pview, it showed blue lines. But when I ran the project, he still goes through the terrain. Do I need more code than what I had in the first post?

Edit: I don’t know how much this matters, but I typed:

fromObject.show()

and this came up:

The white line is in front of the cube, not right below it. If it matters, how would I change that?

Is your cube centred on the origin (0, 0, 0) ?

In the Blender file he is, but I’m not sure about the code. I don’t change his position anywhere in the code, I just loaded in the model.

Hmm… Perhaps try removing the line that reparents your model to the terrain - while it doesn’t seem that doing so should make much difference (and indeed, I’m somewhat grasping at straws in this), it does seem rather odd to me.

If that fails, perhaps we should take a look at your cube model - perhaps paste the egg file (or just its contents, if, as I imagine, it’s short) into this thread.