Bounding box is correct in CGE Editor, but too large at runtime

Hi
In Castle Game Engine Editor, the bounding box looks correct (auto-sized), even during animation.

But at runtime, the bounding box becomes very large,
and this causes unwanted collisions between players

Here is a screenshot showing the difference
Left = CGE Editor (correct bbox), Right = runtime (too large)

How can I force the correct bounding box at runtime
thanks

In this particular case, it seems the debug axis visible on your right screenshot may be an issue? Looks like they cause the bounding box to be larger – as least it seems so from the screenshot.

  1. Solution 1: Simply removing these axes from scene should make the box go smaller.

  2. Solution 2: Rearrange your TCastleTransform hierarchy such that you take bounding box of the character, without this debug axis. The TCastleTransform.BoundingBox is recursive, so it looks at children too.

  3. Solution 3: A hacky and temporary solution may also be to set InternalExcludeFromParentBoundingVolume on these axis, if they are in separate TCastleTransform instances.

    As the name implies, this is internal and you should not rely on this. Doing such “exclude from parent volume” is inherently going to cause rendering issues, because frustum culling and other algorithms will “see” invalid bounding volume, so such excluded thing may incorrectly be culled (invisible) when it should be visible. But it may be acceptable for debug stuff that you don’t care about and will not show to player anyway, like the axis visible here.

    You do this at your own risk – as said above, it may result in rendering artifacts, and InternalExcludeFromParentBoundingVolume may be removed from the engine at some point too.

  4. The one proper, non-hacky solution is: Do not rely on BoundingBox values for your game logic.

    We never guarantee how “tight” is this bounding box, we only guarantee it is large enough to include your model . But it also has to be calculated fast and sometimes this means this BoundingBox can be a bit larger than it really has to. (E.g. this did cause one change in the past, in some edge-cases the box is now larger than it could be, but that’s acceptable as it’s calculated much faster and usually the slightly large box is equally good for our culling purposes.)

    You can add your own explicit boxes to the hierarchy to detect collisions.

    Or, the advised way: use physics colliders, add TCastleBoxCollider or other colliders to your world, and detect collisions using physics, and use ray-casts for physics.

1 Like

Thanks! I’ll try this approach it looks ideal and easy to implement.

1 Like