I’m a bit stuck trying to get a CapsuleCollisionShape CharacterControl to be offset from the model’s centre is not 0,0,0 .
One of two things needs to be achieved:
- The model is offset from the physics bounds.
- The physics bounds is offset from the model.
The problem is that I can’t get the offset, tried using the setLocalTranslation on the model and setPhysicsBounds on the CharacterControl but neither yield the result.
I’m sort of guessing that this is down to the CharacterControl updating the local translation of the model (as it’s the Spatial’s control), so the setLocalTranslation is overriden on the first update.
So my next attempt will be to use a mediator to maintain an offset from the coordinates given by the physics offset.
Does anyone know of a more sensible way of doing this?
Doesn’t really work, you could maybe use a HullCollisionShape or something. Since you can’t use CompoundCollisionShapes you are basically bound to centered collision shapes. What you can do is move the model spatial e.g. as child of a node.
Ah, yes, of course …a Node with the model as a child!
So the solution I used here was:
Created a Node, the CharacterControl and loaded the model.
Node with the Character control added for a control
Added the model’s offset as the local translation
Attached the model to the Node as a child
physicsCharacter = new CharacterControl( new CapsuleCollisionShape( 4.25f, 9.5f ), .1f );
model = assetManager.loadModel( Location.Mesh.url );
model.setLocalTranslation( 0f, -9f, 0f);
controlledModel = new Node();
controlledModel.attachChild( model )
That was much easier then my suggestion - thanks Normen