Hello monkeys
In our project we have specific classes for several LevelElements (like Straights, Curves, Forks or DeadEnds) wich contain one node each with multiple RigidBodyControls added to them. When i try to add these to the PhysicsSpace, there is no error, like a NullPointer or sth that would occour, when there is no Control attached to the node, but the Collision does not work either, i can just “walk through the walls”.
The code for adding the RigidBodyControls to the spatial, (is called after the Node has been added to rootNode) looks like this:
[java]
@Override
protected void addCollisionControlsToNode() {
//------------------PHYSICS und COLLISION--------------------------------------
//Create Collisionshapes for all walls, considering the vertex-arrays defined above
SimplexCollisionShape wallLeftShape = new SimplexCollisionShape(
verticesLeftWall[0], verticesLeftWall[1], verticesLeftWall[2], verticesLeftWall[3]);
SimplexCollisionShape wallRightShape = new SimplexCollisionShape(
verticesRightWall[0], verticesRightWall[1], verticesRightWall[2], verticesRightWall[3]);
SimplexCollisionShape floorShape = new SimplexCollisionShape(
verticesFloor[0], verticesFloor[1], verticesFloor[2], verticesFloor[3]);
SimplexCollisionShape ceilingShape = new SimplexCollisionShape(
verticesCeiling[0], verticesCeiling[1], verticesCeiling[2], verticesCeiling[3]);
//Create RigidBodyControls
RigidBodyControl wallLeftControl = new RigidBodyControl(wallLeftShape, 0);
RigidBodyControl wallRightControl = new RigidBodyControl(wallRightShape, 0);
RigidBodyControl floorControl = new RigidBodyControl(floorShape, 0);
RigidBodyControl ceilingControl = new RigidBodyControl(ceilingShape, 0);
wallLeftControl.setApplyPhysicsLocal(true);
wallRightControl.setApplyPhysicsLocal(true);
floorControl.setApplyPhysicsLocal(true);
ceilingControl.setApplyPhysicsLocal(true);
//Add these to the node
this.node.addControl(wallLeftControl);
this.node.addControl(wallRightControl);
this.node.addControl(floorControl);
this.node.addControl(ceilingControl);
}
[/java]
Afterwards they are being added to PhysicsSpace from within a central function that traverses our LevelElements using:
[java]
bulletAppState.getPhysicsSpace().add(spatial);
[/java]
Creating a simple box and adding this to the PhysicsSpace works by the way.
This is why I assume, that the error may be caused by fact, that the Controls are not being added to the Geometries which define that particular wall like “wallLeft”, but are instead added to the parent node, that contains these geometries and describes the whole LevelElement.
But on the other hand I remember having seen people add Controls directly to nodes, like we do it in our code and I would like you to give me an estimation if this may be the problem or not, before i refactor 50% of our existing code just to recognize, that the mistake was something perfectly different.
So do you think, my theory could be right or does your experience tell you several other common reasons for collision code to misbehave, like mine does?
I will be glad about hints and suggestions of every kind. Thank you.
Best regards
mank319