btCapsuleShape location isn't accurate at all

As i said the issue is related to btCapsuleShape (that btw i was referring to with btCollisionShape by mistake in one of my previous replies).

When you build this shape in bullet the height you specify is relative to the cylinder and not the full shape.
To overcome this the BetterCharacterControl removes 2*radius from the height. But in this way it treats the capsule as if it were a cylinder with two spheres at the extremities, that doesn’t seem to be 100% accurate with bullet native.
If you build the capsule by hand with a cylinder and two spheres, the results are accurate.

This is my BetterCharacterControl.getShape i’ve just modified to test this theory:

    protected CollisionShape getShape() {
        float radius= getFinalRadius();
        float height=getFinalHeight();
        float cylinder_height= height- (2.0f * radius) ;
        CylinderCollisionShape cylinder = new CylinderCollisionShape(new Vector3f(radius, cylinder_height/2f,radius)/*NB constructor want half extents*/,1);
        SphereCollisionShape sphere=new SphereCollisionShape(getFinalRadius());        
        CompoundCollisionShape compoundCollisionShape = new CompoundCollisionShape();
        compoundCollisionShape.addChildShape(sphere,new Vector3f(0,
                /*sphere half height*/radius
        ,0)); // bottom sphere
        compoundCollisionShape.addChildShape(cylinder, new Vector3f(0,
                /*half sphere height*/(radius)+
                /*cylinder half height*/(cylinder_height/2.f)
        , 0)); // cylinder, on top of the bottom sphere
        compoundCollisionShape.addChildShape(sphere,new Vector3f(0,
                /*half sphere height*/(radius)+
                /*cylinder height*/(cylinder_height)
        ,0)); // top sphere       
        return compoundCollisionShape;
    }

Note: I’m not sure if it will behave in the same way the capsule shape does.

2 Likes