Skip to content

Commit

Permalink
fix: physics lite raycast bug (#999)
Browse files Browse the repository at this point in the history
  • Loading branch information
yangfengzzz authored Sep 2, 2022
1 parent 2c32b4f commit 1b6b66c
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions packages/physics-lite/src/shape/LiteBoxColliderShape.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { LitePhysicsMaterial } from "../LitePhysicsMaterial";
export class LiteBoxColliderShape extends LiteColliderShape implements IBoxColliderShape {
private static _tempBox: BoundingBox = new BoundingBox();
private _halfSize: Vector3 = new Vector3();
private _scale: Vector3 = new Vector3(1, 1, 1);

/** @internal */
_boxMin: Vector3 = new Vector3(-0.5, -0.5, -0.5);
Expand Down Expand Up @@ -42,7 +43,7 @@ export class LiteBoxColliderShape extends LiteColliderShape implements IBoxColli
*/
setWorldScale(scale: Vector3): void {
this._transform.position = this._transform.position.multiply(scale);
this._halfSize.multiply(scale);
this._scale.copyFrom(scale);
}

/**
Expand All @@ -60,8 +61,16 @@ export class LiteBoxColliderShape extends LiteColliderShape implements IBoxColli
const localRay = this._getLocalRay(ray);

const boundingBox = LiteBoxColliderShape._tempBox;
boundingBox.min.set(-this._halfSize.x, -this._halfSize.y, -this._halfSize.z);
boundingBox.max.set(this._halfSize.x, this._halfSize.y, this._halfSize.z);
boundingBox.min.set(
-this._halfSize.x * this._scale.x,
-this._halfSize.y * this._scale.y,
-this._halfSize.z * this._scale.z
);
boundingBox.max.set(
this._halfSize.x * this._scale.x,
this._halfSize.y * this._scale.y,
this._halfSize.z * this._scale.z
);
const rayDistance = localRay.intersectBox(boundingBox);
if (rayDistance !== -1) {
this._updateHitResult(localRay, rayDistance, hit, ray.origin);
Expand Down

0 comments on commit 1b6b66c

Please sign in to comment.