[SOLVED] Various Bugs involving RigidBody

Scenario:

I have the player shooting balls which have RigidBodyControl as a control. When the player clicks, it adds a new ball to the ball node, the ball list, and physics space. There is no code that removes balls from any of those. It is similar to the Hello Physics Tutorial example.

The scene is also controlled by RigidBody, so the balls are able to collide with the scene.

Problems:

  1. When two balls collide with each other, they are removed from the ball node and the physics space. There is no code that does that. This never happens when a ball collides with the scene. [SOLVED]

  2. When a ball collides about perpendicular with face of the scene, the collision somehow doesn’t register and the ball goes through the face. I wonder if the balls’ velocity is too much, so the ball “skips” over the face.

Code:

// in class Ball
// initialize ball
public void build(AssetManager manager) {
	Spatial ballSpat = manager.loadModel("Models/Ball.fbx");
	ballSpat.setLocalTranslation(pos);
	ballSpat.setLocalScale(.02f);
	
	Material ballMat = new Material(manager, "Common/MatDefs/Light/Lighting.j3md");
	ballMat.setTexture("DiffuseMap", manager.loadTexture("Models/ball tex.png"));
	ballSpat.setMaterial(ballMat);
		
	ballSpat.addControl(phys);
	phys.setMass(.5f);
	phys.setLinearVelocity(vel);
	phys.setRestitution(100);
		
	node.attachChild(ballSpat);
	id = "ball#"+id;
	node.setName(id);
}
// in simpleInitApp()
// build the scene
Spatial map = assetManager.loadModel("Models/facility.fbx");
map.setLocalScale(.1f, .1f, .05f);
Material mapMat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
Texture warning = assetManager.loadTexture("Models/facility tex.png");
mapMat.setTexture("DiffuseMap", warning);
mapMat.getAdditionalRenderState().setFaceCullMode(RenderState.FaceCullMode.Off);
map.setMaterial(mapMat);
RigidBodyControl mapPhys = new RigidBodyControl(0);
map.addControl(mapPhys);
bulletState.getPhysicsSpace().add(mapPhys);
facilityNode.attachChild(map);
rootNode.attachChild(facilityNode);

There are no exceptions.

1 Like

How do you know they are removed?

(Hint: they are not removed unless you removed them.)

1 Like

bulletAppState.setDebugEnabled(true) says the balls disappeared from the physics space.
System.out.println says they didn’t.
Maybe both balls moved?
Yup, RigidBodyControl.setRestitution(100). It happens that setting the restitution to 100 doesn’t affect the collision with the scene (which is at mass 0).

It “said” it. Like, out loud it says “Hey Codex, these balls are not in the physics space anymore.”

Or they just aren’t displayed anymore?

Keep in mind that there could be a million reasons that balls aren’t displayed anymore but only one reason that they are removed from the physics space.

1 Like

Good point.

Yet it looked an aweful lot like it suddenly not existing. lol

Sounds like you need continuous collision detection:

You mean RigidBody doesn’t already have continuous collision detection?

It’s disabled by default.

Is there a way to enable it? Like rigidBody.enableContinuousCollision() or something like that?

Yes. See the Minie wiki page I linked to above.

Did this problem get solved?

Yes.

2 Likes