1
\$\begingroup\$

What I want to achieve is the player moving to the touched position on a 2D grid-based game, stopping at the last reachable spot if the target position is unreachable. What is the strategy usually adopted in these cases? Should I implement a specific path finding algorithm for the player?

\$\endgroup\$
9
  • \$\begingroup\$ Not sure if there is a usual case which would fit all methods of getting something from point A to point B. It all depends really. for example, an implementation of A* could get you to the closest spot. tutorial here policyalmanac.org/games/aStarTutorial.htm \$\endgroup\$
    – RobM
    Commented Apr 30, 2016 at 14:01
  • \$\begingroup\$ I was already thinking of an A* algorithm -for each node, calculate the distance to the target from the four nodes around, then move to the closest non obstructed of these nodes and repeat- but my main doubt was: If the target is unreachable (say the target is in the water and the player is already near the river) who tells the player to stop there and not continuosly move up and down the river on the two closest non-obstructed nodes? \$\endgroup\$ Commented Apr 30, 2016 at 14:24
  • \$\begingroup\$ Is the target unreachable due to changes after the path was found or was it unreachable at the beginning? \$\endgroup\$
    – Pikalek
    Commented Apr 30, 2016 at 16:11
  • \$\begingroup\$ At the beginning \$\endgroup\$ Commented Apr 30, 2016 at 16:22
  • 1
    \$\begingroup\$ Possible duplicate of How to achieve partial pathfinding? \$\endgroup\$ Commented Sep 8, 2016 at 4:13

1 Answer 1

2
\$\begingroup\$

This question on partial path-finding presents one solution - modify your path finding algorithm to remember the node visited that had the closest estimated distance to the target. Eventually, the path-finding will fail to get a route to the target (since it was unreachable), but you will have a path to the closest point encountered while it searched.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .