Logic question, unique path finding system

Hello everyone,

I’ve been battling with this problem for a while now and haven’t come to any conclusions on how to fix it, the details are as follows.

I’m working on a top down map of the UK which has major locations on it, these locations can be connected via links which can be purchased. What I need is a system to find connections from one location to another using the links, then add them to a list.

Here is the information we have to work with;

  • A list of all the links that’s currently on the map
  • Access to the 1st location the link is connected to and 2nd location the link is connected to.

I just really need help with the logic surrounding this, it’s frying my brain, hehe.

Here is a diagram showing the map and how I need it to work.

As an example for code, I can add all the nearby locations by simply doing this:

foreach(Link e in gameObject.GetComponent<LinkManager>().links){
      if(e.Location1Name == LocationName){
             nearbyLinks.Add(e);
      }
}

Any help is greatly appreciated, I just need someone else’s views on this problem.

Thanks!

Joseph

Honestly, as long as you know the distances between them, and have logic for the connections, you can actually use A*. It’s designed for grids, but the algorithm is versatile enough to be easily modified for node-based pathing. Wikipedia even has a great article on it with pseudocode.

Personally, I would just use Unity’s build in NavMeshAgent.

  1. Attach NavMeshAgent to your UnitObject that moves across the map.
  2. Rotate your map to face up and point the camera down at it.
  3. Set up paths between points to be walkable and bake it.
  4. Set up LocationMarkers on your map
  5. You can then just put UnitObject your map, and set there destination to LocationMarkers on the map and they will walk along the paths.

ProTip: Lock the cameras rotation and use a CharacterController to move it around to ‘scroll’ the map.