Adding RigidBodyControls to a node breaks positioning

Hello there!

We have some problems concerning positioning and collision.
We have defined classes for Elements (Level Elements like Forks, Straights, Curves for a Labyrinth-like game) which implement a Function that returns a node with all geometry info + RigidBodyControls added to it, so the returned node can be added to rootNode and to physicsSpace.

Well so much for the concept… the Problem is: as soon as i implement the collision related code, all elements appear not to get not positioned at all.
//------------------PHYSICS and 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);
    //Add these to the node


Firstly i thought, that setApplyPhysicsLocal would glue the Physics Coordinate System to the one of the specified node, so that whenver the node gets positioned, its control objects will behave the same way, but this does not appear to work out.
I find it strange anyways, that the positioning of the geometries gets affected at all by adding controls to it.

May someone have a hint on how to fix this or why this may happen?

I am looking forward to your answers :slight_smile:

Best Regards


Always attach your geometries to the scene graph (rootNode) before adding RigidBodyControls, this will add them correctly to where the geometry is.

If you create the geometry, set its local translation, then add the RigidBodyControl, it will be added to (0, 0 ,0), as it works in world space, and because the spatial0 follows the RigidBodyControl, it will also move to that position when you attach it to the scene graph afterwards.

Edit: You can also use rigidBodyControl.setPhysicsLocation (Vec3) after adding it like you are doing, if you really want, but you need to know exactly where it needs to go in world space.

1 Like

Thank you very much for this advice :slight_smile:
I am looking forward to implement this tomorrow!
Feedback about my “level of success” will be postet :wink:

Thank you wezrule!
This fixed the whole positioning issue :slight_smile:
But still the collision does not appear to work yet, for these LevelElements.

I described it in a different threat, because it appears to me like a different topic: