# How to check in Unity whether tile B can be reached in a straight line from tile A?

I'm currently trying to smooth out my A* paths based on this article.

This is what I want to achieve:

But sadly I'm stuck at implementing the Walkable method.

I don't know how could I check whether a unit can reach tile B in a straight line from tile A.

(Let's keep it simple, and currently every unit is 1 tile wide.)

• Are you only interested in the math behind it? Have you searched online for formulas that check if a straight line collides with other objects? – TomTsagk Sep 17 '19 at 15:59
• @TomTsagk No, I'm looking for an algorithm which works on tilemaps, and checks whether a 1 tile wide straight line (on which the 1 tile wide unit will walk) is possible between 2 tiles. The math based solution is already implemented in Unity's raycasting I think, but that's too performance heavy in this case, isn't it? – Tudvari Sep 17 '19 at 16:24
• It sounds like you have a working solution (ray/shape casts), and nothing more than a suspicion it's too costly. Please try it first, and ask here once you have an actual measurable performance problem we can help solve. If you're looking for alternative strategies, the typical name for this process is "string pulling", because it's as though your original pathfinding result was a string laid in a zig-zag, and by pulling it taut you eliminate any unnecessary wiggles, to be left with just the most direct path around the obstacles. For navmeshes we often use the Simple Stupid Funnel Algorithm. – DMGregory Sep 17 '19 at 16:53
• @DMGregory Well, I implemented it with raycasting, but currently I have only one enemy, so I don't know how much this will affect performance. Hopefully not much. Thanks for the guidance :) – Tudvari Sep 25 '19 at 22:40
• Okay, then drop 50 enemies in your scene and measure it. This will give you an answer in seconds, rather than waiting hours or days for a human to do this test on your behalf. – DMGregory Sep 25 '19 at 22:43