Fix 3D Physics bugs caused by scaling game objects.#12267
Fix 3D Physics bugs caused by scaling game objects.#12267a-daniel wants to merge 6 commits intodefold:devfrom
Conversation
- 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)
There was a problem hiding this comment.
💡 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; |
There was a problem hiding this comment.
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 👍 / 👎.
- 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)
The problem:
In 3D Physics, scaling game objects causes problems in particular cases:
The solution:
Patched Bullet3D.
Fix #12261
Fix #11246
Fix #11024
Fix #7738
Fix #11308
Technical changes
btCompoundShape::setLocalScalingthe new scale is applied to the unscaled origin.btCapsuleShape:setLocalScaling, the scale is applied only to shape dimensions (m_implicitShapeDimensions) andm_localScalingis kept as 1. This workaround preserves the correct scale required by broad phase(m_implicitShapeDimensions) but by forcingm_localScalingto 1 it solves the problem of the narrow phase applying the scale two times when computing collision depth.btCapsuleShapethe collision margin is not part ofm_implicitShapeDimensionsand is not used in computation of AABB. This way we avoid bloating the shape size in case of high scale values.