Is it possible to add the same RigidBodyControl to multiple Geometries?
In this code, methods buildTop
, buildBottom
, buildLeft
, and builtRight
are creating four walls to a room. All of them are using phys
as the control. I am adding all the Geometries to rootNode, and I’m adding phys
to the same physicsSpace as my player. I can currently run through walls.
buildFloor
builds the floor for my room. It uses floorPhys
as the control. Everything is being attached to rootNode correctly, and floorPhys
is being added to the same physicsSpace as the walls. It is working just fine!
Edit: I’m certain it’s because RigidBodyControl doesn’t like controlling multiple things, because the floor used to be controlled by phys
and it didn’t work then.
private RigidBodyControl phys = new RigidBodyControl(0);
private RigidBodyControl floorPhys = new RigidBodyControl(0);
...
...
protected void buildRoom() {
float wallLength = (size-doorWidth)*0.5f;
Material wallMesh = new Material(manager, "Common/MatDefs/Misc/Unshaded.j3md");
wallMesh.setTexture("ColorMap", manager.loadTexture("Textures/metal01.jpg"));
Box topsShape = new Box(wallLength, height, thickness);
Box sideShape = new Box(thickness, height, wallLength);
buildTop(wallMesh, topsShape, wallLength);
buildBottom(wallMesh, topsShape, wallLength);
buildLeft(wallMesh, sideShape, wallLength);
buildRight(wallMesh, sideShape, wallLength);
buildFloor();
room.setLocalTranslation(pos);
}
...
private void buildRight(Material mesh, Box shape, float length) {
// typical of all the other wall-building methods
Geometry rightTop = new Geometry("right-top wall", shape);
rightTop.setMaterial(mesh);
rightTop.setLocalTranslation(size, height*0.5f, -size+length);
rightTop.addControl(phys);
room.attachChild(rightTop);
Geometry rightBottom = new Geometry("right-bottom wall", shape);
rightBottom.setMaterial(mesh);
rightBottom.setLocalTranslation(size, height*0.5f, size-length);
rightBottom.addControl(phys);
room.attachChild(rightBottom);
}
private void buildFloor() {
Box b = new Box(size, 0.5f, size);
Geometry g = new Geometry("floor", b);
g.setLocalTranslation(pos.x, -height*0.5f, pos.z);
Material mat = new Material(manager, "Common/MatDefs/Misc/Unshaded.j3md");
mat.setTexture("ColorMap", manager.loadTexture("Textures/light005.jpg"));
g.setMaterial(mat);
g.addControl(floorPhys);
room.attachChild(g);
}