Skip to content

fix(physics-2d): account for scale in Box2D joint anchors - #138

Open
orchid-world wants to merge 2 commits into
cocos:v4.0.0from
orchid-world:v4.0.0-fix/box2d-joint-anchor-scale
Open

fix(physics-2d): account for scale in Box2D joint anchors#138
orchid-world wants to merge 2 commits into
cocos:v4.0.0from
orchid-world:v4.0.0-fix/box2d-joint-anchor-scale

Conversation

@orchid-world

@orchid-world orchid-world commented May 20, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Apply each rigid body's node.worldScale when converting Joint2D.anchor and connectedAnchor to Box2D local anchor units.
  • Rebuild joints attached to or connected with a rigid body when that body's scale changes at runtime.
  • Add tests for scaled 2D joint anchors and runtime scale updates.

Issue source: https://forum.cocos.org/t/topic/121887

Re: #

Changelog

  • Fixed Box2D 2D joint anchor offset when rigid body nodes are scaled.

Re: #

Changelog

  • Fixed Box2D 2D joint anchor offset when rigid body nodes are scaled.

Continuous Integration

This pull request:

  • needs automatic test cases check.

    Manual trigger with @cocos-robot run test cases afterward.

  • does not change any runtime related code or build configuration

    If any reviewer thinks the CI checks are needed, please uncheck this option, then close and reopen the issue.


Compatibility Check

This pull request:

  • changes public API, and have ensured backward compatibility with deprecated features.
  • affects platform compatibility, e.g. system version, browser version, platform sdk version, platform toolchain, language version, hardware compatibility etc.
  • affects file structure of the build package or build configuration which requires user project upgrade.
  • introduces breaking changes, please list all changes, affected features and the scope of violation.

- Apply node worldScale to Joint2D anchor and connectedAnchor
- Rebuild affected joints when rigid body scale changes
- Add 2D joint scale and runtime scale tests
@github-actions

github-actions Bot commented May 20, 2026

Copy link
Copy Markdown

Code Size Check Report

Wechat (WASM) Before After Diff
2D Empty (legacy pipeline) 1015126 bytes 1015126 bytes ✅ 0 bytes
2D All (legacy pipeline) 2682844 bytes 2683313 bytes ⚠️ +469 bytes
2D All (new pipeline) 2774681 bytes 2775145 bytes ⚠️ +464 bytes
(2D + 3D) All 10032007 bytes 10032469 bytes ⚠️ +462 bytes
Web (WASM + ASMJS) Before After Diff
(2D + 3D) All 16868425 bytes 16868887 bytes ⚠️ +462 bytes

Interface Check Report

! WARNING this pull request has changed these public interfaces:

@@ -48219,8 +48219,15 @@
     }
     export class Joint2D extends Component {
         /**
          * @en
+         * All registered 2D joints.
+         * @zh
+         * 所有已注册的 2D 关节。
+         */
+        static readonly joints: Joint2D[];
+        /**
+         * @en
          * The position of Joint2D in the attached rigid body's local space.
          * @zh
          * 在自身刚体的本地空间中,Joint2D的位置。
          */

@github-actions

Copy link
Copy Markdown

@orchid-world, Please check the result of run test cases:

Task Details

Platform build boot runned crashScene FailScene
web-mobile PASS PASS FAIL
ios PASS PASS PASS
mac PASS PASS PASS

@github-actions

Copy link
Copy Markdown

@orchid-world, Please check the result of run test cases:

Task Details

Platform build boot runned crashScene FailScene
windows PASS PASS PASS
android PASS PASS PASS
wechatgame PASS FAIL FAIL

@star-e
star-e requested a review from HuazyYang June 2, 2026 10:22
@star-e star-e added the investigation Investigate the impact on the code base label Jun 3, 2026
@star-e

star-e commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

We may use shorter variable names to reduce code size.

@github-actions

Copy link
Copy Markdown

@orchid-world, Please check the result of run test cases:

Task Details

@github-actions

Copy link
Copy Markdown

@orchid-world, Please check the result of run test cases:

Task Details

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

Labels

investigation Investigate the impact on the code base

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants