Closed noocsharp closed 3 years ago
Just found a problem with this, please don't merge until it's fixed.
I had the x and y coordinates swapped, should be good to go now.
I'll add the collides
and interestingFace
checks.
I think the original function returns empty tiles (-1) as well.
Oh, should I send a pull request to fix this?
No, I'm working on it, but thanks.
This PR (choose one or more, ✏️ delete others)
Previously, getRayCastTile relied on getTiles, which retrieves a list of tiles in some rectangle. Not only was this inefficient, but it would cause getRayCastTile to sometimes return an empty array when there were tiles in the ray. Specifically, this bug could be triggered by calling getRayCastTile on a horizontal or vertical line. Since this is converted to a zero width or height, getTiles would return an empty array because
th = 0
ortw = 0
in the for statements:and
meaning these loops would not even start. This behavior makes sense for the getTiles function, but does not for getRayCastTiles. Instead, we get an array of coordinates on the line to check, and simply check if a tile is present at these coordinates.