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:
-
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]
-
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.