fix(physics-2d): account for scale in Box2D joint anchors#138
Open
orchid-world wants to merge 1 commit into
Open
fix(physics-2d): account for scale in Box2D joint anchors#138orchid-world wants to merge 1 commit into
orchid-world wants to merge 1 commit into
Conversation
- Apply node worldScale to Joint2D anchor and connectedAnchor - Rebuild affected joints when rigid body scale changes - Add 2D joint scale and runtime scale tests
Code Size Check Report
Interface Check Report! WARNING this pull request has changed these public interfaces:
@@ -48192,8 +48192,28 @@
*/
connectedBody: RigidBody2D | null;
/**
* @en
+ * Gets the attached body's anchor after node scale is applied, in Box2D local units.
+ * @zh
+ * 获取自身刚体锚点。返回值已经按节点世界缩放换算,并转换为 Box2D 使用的物理单位。
+ * @param out @en Optional output vector. A new Vec2 is created when it is not provided. @zh 可选,输出向量。未传入时会创建新的 Vec2。
+ * @returns @en The scaled local anchor in Box2D units. @zh 已缩放并转换为物理单位的本地锚点。
+ * @internal
+ */
+ _getScaledLocalAnchorA(out?: math.Vec2): math.Vec2;
+ /**
+ * @en
+ * Gets the connected body's anchor after node scale is applied, in Box2D local units.
+ * @zh
+ * 获取连接刚体锚点。连接刚体为空时保持世界原点静态刚体语义,不应用节点缩放;返回值会转换为 Box2D 物理单位。
+ * @param out @en Optional output vector. A new Vec2 is created when it is not provided. @zh 可选,输出向量。未传入时会创建新的 Vec2。
+ * @returns @en The scaled connected local anchor in Box2D units. @zh 已缩放并转换为物理单位的连接锚点。
+ * @internal
+ */
+ _getScaledLocalAnchorB(out?: math.Vec2): math.Vec2;
+ /**
+ * @en
* the Joint2D attached rigid-body.
* @zh
* 关节所绑定的刚体组件。
*/
@@ -48207,8 +48227,17 @@
* @zh
* 此关节的类型。
*/
TYPE: EJoint2DType;
+ /**
+ * @en
+ * Rebuilds all joints whose anchors may be affected by the rigid body's scale.
+ * @zh
+ * 重建所有会受指定刚体缩放影响的关节。
+ * @param body @en The scaled rigid body. @zh 发生缩放变化的刚体。
+ * @internal
+ */
+ static _applyScaleToConnectedJoints(body: RigidBody2D): void;
protected onLoad(): void;
protected onEnable(): void;
protected onDisable(): void;
protected start(): void;
|
|
@orchid-world, Please check the result of
Task Details
|
|
@orchid-world, Please check the result of
Task Details
|
HuazyYang
approved these changes
Jun 3, 2026
HuazyYang
approved these changes
Jun 3, 2026
star-e
approved these changes
Jun 3, 2026
Contributor
|
We may use shorter variable names to reduce code size. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
node.worldScalewhen convertingJoint2D.anchorandconnectedAnchorto Box2D local anchor units.Issue source: https://forum.cocos.org/t/topic/121887
Re: #
Changelog
Re: #
Changelog
Continuous Integration
This pull request:
Compatibility Check
This pull request: