Skip to content

Commit

Permalink
fix: update size error when charactorController disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
luzhuang committed Jul 23, 2024
1 parent 4e3f5a9 commit fe8cbeb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
9 changes: 6 additions & 3 deletions packages/physics-physx/src/shape/PhysXBoxColliderShape.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,12 @@ export class PhysXBoxColliderShape extends PhysXColliderShape implements IBoxCol
const controllers = this._controllers;
for (let i = 0, n = controllers.length; i < n; i++) {
const pxController = controllers.get(i)._pxController;
pxController.setHalfHeight(extents.x);
pxController.setHalfSideExtent(extents.y);
pxController.setHalfForwardExtent(extents.z);

if (pxController) {
pxController.setHalfHeight(extents.x);
pxController.setHalfSideExtent(extents.y);
pxController.setHalfForwardExtent(extents.z);
}
}
}
}
12 changes: 12 additions & 0 deletions tests/src/core/physics/CharacterController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,4 +151,16 @@ describe("CharacterController", function () {
// Test that set collider shape position works correctly.
expect(boxColliderShape.position).to.deep.include({ x: 0, y: 2, z: -1 });
});

it("setSize when disabled", () => {
const controller = roleEntity.getComponent(CharacterController);
controller.enabled = false;
controller.clearShapes();

const boxColliderShape = new BoxColliderShape();
controller.addShape(boxColliderShape);
boxColliderShape.size = new Vector3(1, 1, 1);

expect(boxColliderShape.size).to.deep.include({ x: 1, y: 1, z: 1 });
});
});

0 comments on commit fe8cbeb

Please sign in to comment.