Skip to content

Commit

Permalink
Fix physics lite raycast bug (#999) (#1104)
Browse files Browse the repository at this point in the history
* fix: physics lite raycast bug (#999)
  • Loading branch information
yangfengzzz authored Oct 17, 2022
1 parent 4b8d3b3 commit b391c74
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
2 changes: 0 additions & 2 deletions packages/core/src/physics/DynamicCollider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,6 @@ export class DynamicCollider extends Collider {
const { transform } = this.entity;
const { worldPosition, worldRotationQuaternion } = transform;
(<IDynamicCollider>this._nativeCollider).getWorldTransform(worldPosition, worldRotationQuaternion);
transform.worldPosition = worldPosition;
transform.worldRotationQuaternion = worldRotationQuaternion;
this._updateFlag.flag = false;
}
}
Expand Down
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 b391c74

Please sign in to comment.