[Solved] How to center collitionShape and Geometry

Hi



I know that CollitionShape use the geometry’s origin as its origin point (see image). How can I center the CollitionShape and the Geometry on Bullet B?



[java]

// Bullet 2: box shape (geometry’s origin is on left)

Spatial bullet2_mesh_box = assetManager.loadModel(“Models/bullet/bullet2.j3o”);

bullet2_mesh_box.setName(BULLET_NAME);

bullet2_mesh_box.setMaterial(bullet_material);



BoxCollisionShape boxShape2 = new BoxCollisionShape(new Vector3f(1.5f, 1, 1));



RigidBodyControl bulletBoxShapeControl2 = new RigidBodyControl(boxShape2, 0.25f);

bullet2_mesh_box.addControl(bulletBoxShapeControl2);

bulletBoxShapeControl2.setPhysicsLocation(new Vector3f(-1, 1, -3));



rootNode.attachChild(bullet2_mesh_box);

bulletAppState.getPhysicsSpace().add(bullet2_mesh_box);



bulletBoxShapeControl2.setGravity(Vector3f.ZERO);



// Insert Code here:

// bulletBoxShapeControl2.setPhysicsLocation(…);

// bullet2_mesh_box.setLocalTranslation(…);

[/java]



[java]bulletBoxShapeControl2.setPhysicsLocation(…);[/java] moves the geometry too.

[java]bullet2_mesh_box.setLocalTranslation(…);[/java] does nothing. I think this is the right method to use but it doesn’t work.



Just I want to know if there is a way to do this by code (not changing geometry’s origin on blender).



Thanks,



H

  1. Add your Geometry to a parent node.
  2. Add the RigidBodyControl to the parent node instead.
  3. Offset the Geometry from the parent node with the setLocalTranslation method on it.
2 Likes

Thanks @kwando