From 51ed427006f4cb39d34fdd4abadc8542d4229011 Mon Sep 17 00:00:00 2001 From: James Chen Date: Mon, 18 Nov 2024 18:04:24 +0800 Subject: [PATCH] Also need to consider changing type back to Animated. --- cocos/physics-2d/box2d-wasm/physics-world.ts | 12 +++++++----- cocos/physics-2d/box2d/physics-world.ts | 12 +++++++----- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/cocos/physics-2d/box2d-wasm/physics-world.ts b/cocos/physics-2d/box2d-wasm/physics-world.ts index 9311aa38f94..f00ff3c0dde 100644 --- a/cocos/physics-2d/box2d-wasm/physics-world.ts +++ b/cocos/physics-2d/box2d-wasm/physics-world.ts @@ -346,13 +346,15 @@ export class B2PhysicsWorld implements IPhysicsWorld { } public _updateBodyType$ (body: B2RigidBody2D): void { - if (!this._animatedBodies.includes(body)) { - return; - } - + const animatedBodies = this._animatedBodies; const comp = body.rigidBody; if (comp.type !== ERigidBody2DType.Animated) { - js.array.remove(this._animatedBodies, body); + js.array.remove(animatedBodies, body); + } else { + if (animatedBodies.includes(body)) { + return; + } + animatedBodies.push(body); } } diff --git a/cocos/physics-2d/box2d/physics-world.ts b/cocos/physics-2d/box2d/physics-world.ts index d8370e07a9b..62dca2ec6d9 100644 --- a/cocos/physics-2d/box2d/physics-world.ts +++ b/cocos/physics-2d/box2d/physics-world.ts @@ -327,13 +327,15 @@ export class b2PhysicsWorld implements IPhysicsWorld { } public _updateBodyType$ (body: b2RigidBody2D): void { - if (!this._animatedBodies.includes(body)) { - return; - } - + const animatedBodies = this._animatedBodies; const comp = body.rigidBody; if (comp.type !== ERigidBody2DType.Animated) { - js.array.remove(this._animatedBodies, body); + js.array.remove(animatedBodies, body); + } else { + if (animatedBodies.includes(body)) { + return; + } + animatedBodies.push(body); } }