Hi, I got a problem with the type of my CollisionShapes. I’m working on a board game where you should snap your stones in the midst of the board. In the middle is a little hole, which brings the most points.
I have 3 kinds of objects in the game: the board, some bouncers and the stones.
Now to my problem. I defined these objects with the following code (" ** " just to emphasize):
board
Spatial boardSpat = assetManager.loadModel("Models/board/board.j3o");
**CollisionShape boardShape = CollisionShapeFactory.createDynamicMeshShape(boardSpat);**
Node boardNode = PhysicsHelper.createPhysicsNode(assetManager, boardShape, 0);
boardNode.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(0.0f, -0.2f, 0f)); //0.4 height
boardNode.getControl(RigidBodyControl.class).setApplyPhysicsLocal(true);
mat_board = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
mat_board.setTexture("DiffuseMap", assetManager.loadTexture("Models/board/crokinole cut.png"));
boardSpat.setMaterial(mat_board);
boardSpat.setShadowMode(ShadowMode.Receive);
boardNode.attachChild(boardSpat);
bulletAppState.getPhysicsSpace().add(boardNode);
rootNode.attachChild(boardNode);
bouncers
Spatial bouncerSpat = assetManager.loadModel("Models/bouncer/bouncer.j3o");
**CollisionShape bouncerShape = CollisionShapeFactory.createDynamicMeshShape(bouncerSpat);**
Node bouncerNode = PhysicsHelper.createPhysicsNode(assetManager, bouncerShape, 0);
bouncerNode.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(0.0f, -0.2f, 0f));
bouncerNode.getControl(RigidBodyControl.class).setApplyPhysicsLocal(true);
bouncerSpat.setMaterial((Material) assetManager.loadMaterial("Materials/iron.j3md"));
bouncerSpat.setShadowMode(ShadowMode.Receive);
bouncerNode.attachChild(bouncerSpat);
rootNode.attachChild(bouncerNode);
bulletAppState.getPhysicsSpace().add(bouncerNode);
and stones
stoneSpat = am.loadModel("Models/stone/stone.j3o");
**CollisionShape stoneShape = CollisionShapeFactory.createDynamicMeshShape(stoneSpat); //0.32 height**
stoneNode = PhysicsHelper.createPhysicsNode(am, stoneShape, 20.0f); // 3.0f vorher
stoneGhost = new GhostControl(stoneShape);
As you can see, all 3 objects have dynamic CollisionsShapes. As long as they’re defined like that, the game is working and setImpulse() (which uses applyImpulse() on the stones) is working. But the hole doesn’t have any effects on the stones, i.e. they’re just gliding above.
If I now define the board and bouncers like this
CollisionShape boardShape = CollisionShapeFactory.createMeshShape(boardSpat);
(without dynamic), than the hole is working, but the stones are just flipping around randomly with setImpulse(). I don’t change anything else.
Here is the Code of setImpuse():
public void Impulse(float force, float angle, float width) {
force = force / (width * 0.45f) * 400;
System.out.println(force + " " + angle);
angle = angle / (width * 0.45f) * 400;
float c = (float) (this.angle);
angle = 0.225f * angle - 45.0f;
Vector3f v1 = Translate.posToVector(force * -1f, c - angle, 0.0f);
Vector3f v2 = Translate.posToVector(0.0f, 0.0f, 0.0f);
this.stoneNode.getControl(RigidBodyControl.class).applyImpulse(v1, v2);
}
I really appreciate help and if you need any more information, ask me please.