The built-in physics system and terrain penetrations

I’m using panda’s collision system for a similar project, but I’m testing a collision sphere into collision polygons so my solution might not work in your case. I handle collisions using a CollisionHandlerQueue: when a collision is detected I determine how far the “from” object has penetrated into the “into” object and then correct its position by this depth so that the surface of the “from” object is just touching the surface of the “into” object when the next frame is rendered. In my case this prevents the collision sphere from ever sinking into the surface of the polygon and getting stuck there.

Here’s the gist of the code I use:

def handle_collision(self, obj):
    # Get collision info.
    obj.col_handler.sortEntries()
    entry = obj.col_handler.getEntry(0)
    into_np = entry.getIntoNodePath()
    from_np = entry.getFromNodePath()

    # Calculate collision depth.
    col_surface_pt = entry.getSurfacePoint(from_np)
    col_interior_pt = entry.getInteriorPoint(from_np)
    col_depth = col_surface_pt - col_interior_pt

    # Correct position of object.
    obj.setPos(from_np, -col_depth)

I just pieced this together from a larger algorithm so I doubt it would work as is, but maybe you could apply something like it to your problem.