@adatechnology/game-terrain 0.7.0 → 0.7.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -449,7 +449,8 @@ interface TerrainImplOptions {
449
449
  }
450
450
  /**
451
451
  * The ground as an object of the destruction world (`DestructionWorld.register`): shots, blows, blasts and flames reach it through the world's own raycast and blast like anything else.
452
- * The collision part is a flat box; a ray that enters it goes on to the real surface, so a round fired into a crater lands on its floor.
452
+ * The collision part is a flat box that only says where to look: the world's raycast asks `surfaceRay`, which follows the ground as it is now (craters, heaps),
453
+ * so a round fired into a crater meets its floor, not the flat top of the box over it.
453
454
  */
454
455
  declare function createTerrainImpl(terrain: Terrain, options: TerrainImplOptions): DestructibleImpl;
455
456
 
@@ -1636,6 +1636,7 @@ var GameTerrain = (() => {
1636
1636
  var PART_DEPTH = 3;
1637
1637
  var RAY_BACKOFF = 1;
1638
1638
  var GROUND_HP = 1e12;
1639
+ var HEAP_REACH = 3;
1639
1640
  function createTerrainImpl(terrain, options) {
1640
1641
  const { id } = options;
1641
1642
  const [x0, z0, x1, z1] = terrain.bounds;
@@ -1686,10 +1687,23 @@ var GameTerrain = (() => {
1686
1687
  const onGround = terrain.raycast(from, hit.direction, RAY_BACKOFF + PART_DEPTH);
1687
1688
  return onGround ? { ...hit, point: onGround.point } : hit;
1688
1689
  };
1690
+ const surfaceRay = (ray) => {
1691
+ if (ray.ignored?.(PART_ID)) return null;
1692
+ const [ox, oy, oz] = ray.origin;
1693
+ const [dx, dy, dz] = ray.direction;
1694
+ const enter = dy < 0 ? Math.max(0, (oy - HEAP_REACH) / -dy) : oy <= HEAP_REACH ? 0 : Infinity;
1695
+ const leave = dy < 0 ? (oy + PART_DEPTH) / -dy : Math.hypot(x1 - x0, z1 - z0) + Math.hypot(ox - (x0 + x1) / 2, oz - (z0 + z1) / 2);
1696
+ const far = Math.min(ray.maxDistance, leave);
1697
+ if (!(enter <= far)) return null;
1698
+ const hit = terrain.raycast([ox + dx * enter, oy + dy * enter, oz + dz * enter], ray.direction, far - enter);
1699
+ if (!hit) return null;
1700
+ return { part: PART_ID, point: hit.point, normal: hit.normal, distance: enter + hit.distance, pathLen: PART_DEPTH };
1701
+ };
1689
1702
  return {
1690
1703
  id,
1691
1704
  ...options.name ? { name: options.name } : {},
1692
1705
  describe: spec,
1706
+ surfaceRay,
1693
1707
  hit(hit) {
1694
1708
  const landed = resolve(hit);
1695
1709
  const result = terrain.applyHit(landed);