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

This is what I want to achieve:

enter image description here

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.)

  • \$\begingroup\$ 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? \$\endgroup\$ – TomTsagk Sep 17 '19 at 15:59
  • \$\begingroup\$ @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? \$\endgroup\$ – Tudvari Sep 17 '19 at 16:24
  • 1
    \$\begingroup\$ 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. \$\endgroup\$ – DMGregory Sep 17 '19 at 16:53
  • \$\begingroup\$ @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 :) \$\endgroup\$ – Tudvari Sep 25 '19 at 22:40
  • \$\begingroup\$ 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. \$\endgroup\$ – DMGregory Sep 25 '19 at 22:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.