- Home /
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
Answer by FortisVenaliter · May 20, 2016 at 08:02 PM
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.
wow, I never thought of it like that, thanks a bunch!
I'll take a look at the system and get something worked out.
Seriously, thanks again!
It's actually the other way round. A* is generally for node graphs. Though any kind of grid represents a regular node graph. Grids simplifies the concept of neighbor nodes as the grid position already tell which neighbors a certain node has.
Answer by ninja_gear · May 20, 2016 at 08:24 PM
Personally, I would just use Unity's build in NavMeshAgent.
Attach NavMeshAgent to your UnitObject that moves across the map.
Rotate your map to face up and point the camera down at it.
Set up paths between points to be walkable and bake it.
Set up LocationMarkers on your map
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.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Foreach loop doesn't run 2 Answers
Foreach loop inside FileStream 1 Answer
foreach-loop. Is there a gameobject with position existing? 3 Answers