Hello Guys,
I’m participating in a small game jam and I’m trying to calculate the height parameter to use with the CapsuleCollisionShape. Here is the current code:
CapsuleCollisionShape capsule = new CapsuleCollisionShape(radius, height);
CharacterControl charCtl = new CharacterControl(capsule, stepHeight);
I’m trying to calculate the height parameter according to a given size of the model I would like to use as a character in my game.
And set the height variable as the CapsuleCollisionShape height in the constructor. But there is not always a match… If I scale / unscale the model then the Bounding Box’s yExtent cannot be used as height for the CapsuleCollisionShape .
It’s easy to manually tune the CapsuleCollisionShape height to fit my model but when I scale / unscale the model I want to be able to re-calculate the CapsuleCollisionShape height and I can’t find the correct formula.
what do you think? Anyone tried calculating CapsuleCollisionShape for a given model?
Thanks
The “height” in the constructor and getHeight() method refers to the height of the cylindrical portion of the capsule before the scale factor is applied.
Perhaps you want to set the total height of the capsule, which would be
OK guys I have found the problem! Maybe it will help someone in the future using the CharacterControl & CapsuleCollisionShape.
The key is that you cannot just manipulate the capsule height. You must change the radius as well for example if you scale your model by 0.5 (half the size) , you need to multiply both the capsule height & radius by 0.5. My main issue was that I changed only the capsule’s height.
The second problem in my code was that I scaled the Geometry and not its parent node. I think it is best practice when dealing with scaling to always scale the parent node (if you have one). I fixed that as well but again the key point for fixing this issue was to change both capsule’s height & radius.