theripper93 / Levels

22 stars 13 forks source link

Possible issue with ceiling/floor collision test #111

Closed caewok closed 1 year ago

caewok commented 1 year ago

In SightHandler.prototype.testCollision, the code is supposed to loop through the tile planes and check for ceiling and floor collisions:

   for (let tile of canvas.tiles.placeables) {
      if(tile.document.flags?.levels?.noCollision) continue;
      const bottom = tile.document.flags?.levels?.rangeBottom ?? -Infinity;
      const top = tile.document.flags?.levels?.rangeTop ?? Infinity;
      if (bottom != -Infinity) {
        const zIntersectionPoint = getPointForPlane(bottom);
        if (
          ((z0 < bottom && bottom < z1) || (z1 < bottom && bottom < z0)) &&
          tile.containsPixel(zIntersectionPoint.x, zIntersectionPoint.y, 0.99)
        ) {
            return {
              x: zIntersectionPoint.x,
              y: zIntersectionPoint.y,
              z: bottom,
            };
        }
      }
    }

I cannot tell what, if anything, the top variable is supposed to be doing. It appears to be unused. Which makes me think that maybe there is a missing test for top or maybe some of the bottom variables in the inner if loop should test top instead of bottom.

theripper93 commented 1 year ago

The top does not do anything, it was kept for compatibility and for other modules to use but the test is not meant to test the ceiling, although it was doing that in v10 but I decided to remove it since it was creating more confusion than anything else and no longer made sense for how v10 levels operates