I’m posting this because I’ve tried everything that I can find in the examples and forum posts, but I can’t figure out what’s causing this issue. When I attempted to scale up the size of the bricks’ geometries, I begin having problems that appear to be related to collisions. The bricks are falling through the floor and behaving erratically. I have tried adjusting .setCcdMotionThreshold(value), .setAccuracy(someOtherValue), .setMaxSubSteps(yetAnotherValue), for various combinations of values on both the bricks, floor, and scene. I have tried removing the floor. I have spaced out the bricks to ensure they are not creating impossible overlaps. In the video, it is clear that the material did not scale with the geometry, so I’m sure that I’m either missing a step or doing something wrong.
Here is the video:
[video]- YouTube
Here is brick code:
[java]public void makeBrick(Vector3f loc, Box box, Material wall_mat, RigidBodyControl brick_phy) {
/** Create a brick geometry and attach to scene graph. /
Geometry brick_geo = new Geometry(“brick”, box);
brick_geo.setMaterial(wall_mat);
this.getRootNode().attachChild(brick_geo);
/* Position the brick geometry /
brick_geo.setLocalTranslation(loc);
/* Make brick physical with a mass > 0.0f. /
brick_phy = new RigidBodyControl(4f);
//brick_phy.getCollisionShape().setScale(new Vector3f(2,2,2)); // Won’t work as this is now a CompoundCollisionShape containing a MeshCollisionShape
/* Add physical brick to physics space. */
brick_geo.addControl(brick_phy);
// You must scale the geometry for the scale change to work.
brick_geo.getControl(RigidBodyControl.class).getCollisionShape().setScale(new Vector3f(2,2,2)); // Now it should work.
this.getBulletAppState().getPhysicsSpace().add(brick_phy);
// this.getBulletAppState().getPhysicsSpace().setAccuracy(1f/60f); // Specifies physics accuracy. The higher the accuracy, the slower the game. Increase value if objects are passing through one another, or bounce oddly.
brick_geo.getControl(RigidBodyControl.class).setCcdMotionThreshold(0.1f); // Do this if needed.
//this.getBulletAppState().getPhysicsSpace().setMaxSubSteps(2);
}
// how do I check if the bulletAppState contains the RigidBodyControl?
public void makeBrickWall(Box box, Material wall_mat, RigidBodyControl brick_phy) {
float startpt = brickLength / 4;
float height = 0;
for (int j = 0; j < 15; j++) {
for (int i = 0; i < 6; i++) {
Vector3f vt =
new Vector3f(i * brickLength * brickMultiplier * 2 + startpt, brickHeight * brickMultiplier + 40 + height, 0);
makeBrick(vt, box, wall_mat, brick_phy);
}
startpt = -startpt;
height += 2 * brickHeight * brickMultiplier;
}
}[/java]
The remaining code is here: https://github.com/devinbost/jMathGame3d.git