I got this idea to develop but I cant get my head around this (beginner really). What you can see on the image is a map with locations (big circles) and bunch of connections with “stops”.
What I would like is when i drag my player from one location to another, to calculate a shortest ‘route’ and then, every turn (game is turn based) advance one stop toward final destination.
What i have for now is for each of the locations (the big circle one), i have a class :
[System.Serializable]
public class Connection
{
public Location NeighborLoc;
public int Distance;
}
public Connection[] connections;
Where for each of the locations i have a list of “neighbor” locations with fixed distance to them (int) - basically a number of small white circles (“stops”).
Then i have a function :
public void CalculateRoute(Location from, Location where)
But, whatever i do in this f-ion I end up in a infinite loop, crash unity or, just never calculate a route :).
I tried basically going trough all connections for a location, then for each of those connections, find an endpoint and recursively call CalculateRoute on that location and ‘where’ locations, this usually ends up as an infinite loop, and, even then, I’m not sure how to go from there (how to find a shortest route, and ‘store’ this route for later advancing every turn, how to avoid turning back to start location). I’m guessing I should take a totally different approach here (some kind of pathfinding or something?? )
Thanks for any help ![]()
