CharacterControl's Collision Shape Parameters?

Whats the best way to get the parameters for capsulecollisionshape for your physics Character controller. Currently I used boundingbox of the character using YExtent for the height and using which ever extent is greater X or Z for the radius. I’ve always used it this way but some characters are floating now which is odd; however i figured theirs probably a better way to do it after all of this time.



[java]

com.jme3.bounding.BoundingBox bb = (com.jme3.bounding.BoundingBox) spatial.getWorldBound();

float radius = bb.getXExtent() > bb.getZExtent() ? bb.getXExtent() : bb.getZExtent();

float height = bb.getYExtent();

character = new CharacterControl(new CapsuleCollisionShape(radius, height), height / 3);

character.setGravity(character.getGravity() * 3f);

character.setJumpSpeed(height * 15f);

spatial.addControl(character);

//Director.getPhysicsSpace().addCollisionListener(this);

Director.getPhysicsSpace().add(character);

[/java]

the boundingbox is going to give you the closest approximation. Make sure the bounding box looks right in the scene composer, it can be screwed up sometimes. I would add the character control to a node, and add that spatial to the node and move the spatial up, as much as you require to make it above the ground.

Well it is above the ground. Its not a problem really of the capsule not encompassing the model its just to make a test case for somehthing I was doing and to rule out a fault of the model I decided to use Sinbad which i found using the physicsDebugger creates a capsule at least twice his size and places him in the middle in which I have to half the height and subtract from it a little to get it visibly on the floor. Of course this isn’t present with the other models I have but i was wondering in case it came up at a later time with any new assets

The capsule is peculiar… When experimenting with it I had the feeling you have to subtract 2*r from a value you want to set as absolute height to get the desired result as it doesn’t account for the two half spheres at the top and bottom somehow…

1 Like

hmm oddly enough if i try something like below it pretty much flushes with the floor. I should probably test this with the all of the other models and see how it pans out.

[java]

float height = bb.getYExtent()/2-diameter/4;

[/java]