- Home /
2D TileMap: Determining which grid tiles a line passes over
Hello all,
I'm familiar with RayCastAll, which is great for tracking which game objects a line passes through, but I'm struggling to work out the best way to monitor which grid tiles on a tilemap a line passes over between 2 points.
If (for example) a room has multiple pillars, each of which use the Tilemap Collider, there is a problem where RayCastAll only returns the first pillar it comes across - and ignores the others.
Which is not robust enough. I need to know all instances of tilemap walls/pillars along a line between 2 points.
Is the only option going to be doing a Mathf.FloorToInt on a loop every few dots along the distance from the start to end point? Then checking my tile array for the tile type?
I guess that would work, but it seems a rather messy long-winded solution. It would just be so much easier if RayCastAll would log each occasion it hits the tilemap collider instead of just the first! (Which would instantly solve my problem).
Any advice greatly appreciated.