[SOLVED] Collision problem with sphere and boxes

Hi,

I have a moving object for which I defined a collision sphere and 2 cubes with their corresponding bounding boxes. The space between the cubes is very small, the moving object should not be allowed to pass between them. To detect the collisions I’m using a CollisionHandlerPusher, but the moving object manages to pass between the cubes.

I defined another camera on top of the scene and when looking at the collisions I see there are 2 of them at each moment, one with the first cube and another with the second one. I can also see that the moving object is moved rapidly between 2 positions, probably the ones where is pushed by the collided objects.

Is this normal? Is there a fix or a workaround for this?

Thanks & best regards,
Dumi.

Cubes are hard, because they have lots of different surfaces, all of which are pushing your sphere in different directions. When you get two cubes with a tiny space between them, you have twelve different faces which all want to push on your sphere. The collision system isn’t always able to resolve which faces are the most important.

It’s best to simplify your collision surfaces to the minimum structures that you actually require to keep your sphere where it belongs. Instead of two cubes, make two walls (two polygons). And make sure there isn’t a gap between the two walls–the polygons should meet precisely at the vertices. Even better, make only one polygon if you can.

Or, use spheres universally instead of cubes. Spheres don’t have the problem that cubes have, because a sphere is itself a well-defined solid, instead of six loosely-coupled polygons.

David

Or simply switch to Bullet Physics. It comes along with boxes pretty well.

Ok, I took a different approach. Since the cubes are next to each other and aligned I created a supernode containing them all. And I’m using the newly created node bounding box for collision:

    NodePath shelf = window->load_model(framework.get_models(), "shelf");
    LPoint3 min;
    LPoint3 max;
    shelf.calc_tight_bounds(min, max);
    size = max - min;

    stringstream ss;
    NodePath placeholder;
    
    for (int i = 0; i < 5; i++) {
        ss << i;
        placeholder = right_np.attach_new_node("right" + ss.str());
        placeholder.set_pos(4, i * size.get_y() + 10, 0);
        shelf.instance_to(placeholder);
        
        placeholder = left_np.attach_new_node("left" + ss.str());
        placeholder.set_pos(-4, i * size.get_y() + 10, 0);
        placeholder.set_h(180);
        shelf.instance_to(placeholder);
    }

    initCollisionBox(right_np);
    initCollisionBox(left_np);

Thanks & best regards,
Dumi.