Skip to content

Fix 3D Physics bugs caused by scaling game objects.#12267

Open
a-daniel wants to merge 6 commits intodefold:devfrom
a-daniel:issue-12261-bullet3d-bugs-due-to-scaling
Open

Fix 3D Physics bugs caused by scaling game objects.#12267
a-daniel wants to merge 6 commits intodefold:devfrom
a-daniel:issue-12261-bullet3d-bugs-due-to-scaling

Conversation

@a-daniel
Copy link
Copy Markdown

@a-daniel a-daniel commented Apr 22, 2026

The problem:
In 3D Physics, scaling game objects causes problems in particular cases:

  1. Scale > 1 and collision shape position != (0,0,0) => collision object might fly away on contact
  2. Scale > 1 and collision shape is capsule => collision object bounces really fast on contact
  3. Scale < 1 and collision shape is capsule => collision detection happens later than expected (requires significant overlap between objects).
  4. Collision shape is capsule and scale > 1 and physics scale < 1 => collision shape unexpectedly increases in size .

The solution:
Patched Bullet3D.

Fix #12261
Fix #11246
Fix #11024
Fix #7738
Fix #11308

Technical changes

  • In btCompoundShape::setLocalScaling the new scale is applied to the unscaled origin.
  • In btCapsuleShape:setLocalScaling, the scale is applied only to shape dimensions (m_implicitShapeDimensions) and m_localScaling is kept as 1. This workaround preserves the correct scale required by broad phase(m_implicitShapeDimensions) but by forcing m_localScaling to 1 it solves the problem of the narrow phase applying the scale two times when computing collision depth.
  • In btCapsuleShape the collision margin is not part of m_implicitShapeDimensions and is not used in computation of AABB. This way we avoid bloating the shape size in case of high scale values.

- in btCompoundShape: fixed wrong scaling of child shape origin
- in btCapsuleShape: force m_localScaling to 1(now, scale affects only the shape geometry, through m_implicitShapeDimensions)
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4c8d807c5a

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".


m_implicitShapeDimensions = (unScaledImplicitShapeDimensionsWithMargin * m_localScaling) - oldMargin;

m_implicitShapeDimensions = (unScaledImplicitShapeDimensionsWithMargin * scaling) - oldMargin;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Preserve absolute scale when updating capsule dimensions

This change applies scaling directly to m_implicitShapeDimensions after removing btConvexInternalShape::setLocalScaling(scaling), which previously normalized scale via absolute(). As a result, negative uniform scales now produce negative capsule radius/half-height, creating invalid geometry and unstable contacts. This is reachable in Defold’s 3D sync path because physics_3d.cpp forwards GetUniformScale() into setLocalScaling(...); mirrored objects (for example scale -1) will now feed negative values into this assignment.

Useful? React with 👍 / 👎.

@britzl britzl requested a review from JCash April 22, 2026 15:22
a-daniel added 3 commits May 1, 2026 07:46
- in btCapsuleShape, changed the collision margin to be equal to radius and not be included in the implicit shape (same as Bullet 3.25 capsule shape)
@CLAassistant
Copy link
Copy Markdown

CLAassistant commented May 1, 2026

CLA assistant check
All committers have signed the CLA.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants