a) When I animate a character, the ray casts still have the initial model.
Is it possible to simply update the shape after each frame? Or only (and possibly the best) once the animation is complete?
b) When I simply use spatial.move() on a submesh to move the walls, the collisionshape seems to be the old one.
Can I recalculate it aswell?
Edit: I tried CollisionShapeFactory.createMeshShape(worldSpatial); on both: The SubGeometry or the whole world. Using the debug-mode I can see that the mesh shape isn’t updated though.
And a): Will that take the animation into account?
Sorry for that confusing post. I’ve made some progress right now.
One needs worldSpatial.getControl(RigidBodyControl.class).setCollisionShape(CollisionShapeFactory.createMeshShape(worldSpatial)); to actually update the CollisionShape.
The Problem is: This is recalculating the Shape for the whole level which is cpu-intensive.
There is the CSF.shiftCompoundShapeContents but since the SubMesh does not contain a RigidBodyControl I am uncertain how to set the CollisionShape or how to recalculate that sub-shape?
Aditionally, if I remove a submesh using .removefromParent() I get a nullPointerException at com.bulletphysics.collision.shapes.CompoundShape.getChildShape(CompoundShape.java:113)
Potentionally because that Node isn’t there any longer.
Do I need to remove the Shape somehow?
b) Simply create separate collision shapes instead of the compound shape from the CollisionShapeFactory if you already have separate geometries. Then the shape can move with the geometry (or move the geometry).
Okay, but how can I do that?
I now tried to add a RigidBodyControl to that SubMesh and then again a RigidBodyControl on it’s parent.
Unfortunately the parent’s RBC does not care if the SubMesh already has a CollisionShape and adds one itself…
You maybe want to have one main node containing most of the map and one for dynamic elements.
The main node would work as it currently does and the secondary node, you would create a rigidbody for each element.
Then, you can move those elements using the setPhysicsLocation. Ideally, walls would move with impulses, but that might be hard to achieve without them falling flat.