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); } }