[SOLVED] thin BoxCollisionShape cannot to be laid flat on HullCollisionShape plane

Hello everyone,
I have a strange problem: Why the thin “BoxCollisionShape” box cannot to be laid flat on the “HullCollisionShape” plane?

1. The “HullCollisionShape” plane:

public void setConvexRigidBody(Spatial spatial) {
	List<Vector3f> list = new ArrayList<Vector3f>();
	list.add(new Vector3f(0f, 0.1f, -2f));
	list.add(new Vector3f(0f, 0.1f, 2f));
	list.add(new Vector3f(-5f, 0.1f, 0f));
	list.add(new Vector3f(0f, 0.2f, -2f));
	list.add(new Vector3f(0f, 0.2f, 2f));
	list.add(new Vector3f(-5f, 0.2f, 0f));
	HullCollisionShape hullPiece = new HullCollisionShape(getPointsData(list));
	hullPiece.setMargin(0.0f);
	RigidBodyControl rigid = new RigidBodyControl(hullPiece, 0);
	spatial.addControl(rigid);
	bulletAppState.getPhysicsSpace().add(rigid);
}
protected float[] getPointsData(List<Vector3f> dataList) {
	float[] data = new float[dataList.size()*3];
	for (int i = 0; i < dataList.size(); i++) {
		data[i*3+0] = dataList.get(i).x;
		data[i*3+1] = dataList.get(i).y;
		data[i*3+2] = dataList.get(i).z;
	}
	return data;
}

2. The thin “BoxCollisionShape” box:

public void setBoxRigidBody(Spatial spatial) {
	RigidBodyControl rigid = new RigidBodyControl(1f);
	CollisionShape boxShape = CollisionShapeFactory.createBoxShape(spatial);
	rigid.setCollisionShape(boxShape);
	spatial.addControl(rigid);
	bulletAppState.getPhysicsSpace().add(rigid);
}

This is contradictory! Physical engine suggests to use a positive margin (zero margin might introduce problems), but in this case, positive margin introduced problems.
In fact, I have to create BoxShape with positive margin, so I wonder how to solve this problem when using the positive margin to create BoxShape.

https://pybullet.org/Bullet/phpBB3/viewtopic.php?f=9&t=13053

Thanks!

1 Like
1 Like

As to your question, it could be related to floating point precision and the “giant triangle” in that collision shape. Contacts are going to have floating point errors across a single large shape.

Others with more bullet experience may be able to comment more specifically.

Thanks for your quick reply and guidance.

BoxCollisionShape is a precise shape. Its margin lies entirely inside the box. Therefore, each dimension of the box should be more than the margin.

If I understand what you did, you created boxes with thickness=0.036 and margin=0.04. I suspect that reducing the margin of each box to 0.01 will resolve the issue. Even better would be to “scale the world” by 4x, making everything larger so that it’s not necessary to tinker with margins.

I have nothing to add, but I want to say how spectacular your documentation is for Minie, Stephen.

1 Like

Is the problem solved?

Thank you so much, Mr. Stephen. Sorry for the late reply.

The problem seem to be solved after setting margin = 0.018f. Because of other project, I haven’t tested it in more detail.

By the way, your documentation for Minie is so great! Thanks again.

1 Like