I am using PathfindingService to create paths between points. I have the costs set up so that the agent prefers Asphalt (the road material) over anything else. I am trying to figure out how to keep the path on the correct side of the road (that would be the right for my purposes).
Make the costs for going on the left side of the road higher. You’re going to have to manually assign where they have to go for all the roads (just like irl, there’s a “hard coded” direction you have to follow)
Separate this into a pathfinding step, which you already have, and a steering step. The steering step should use the selected path to determine the current and next road. It should use the current movement direction and road segment to generate the target position, on the correct side of the road.
I see you’re using the material cost and assigning asphalt. You can also do something similar with any part using a PathfindingModifier. So basically make a “right” and “left” side of the road where players prefer to go on the right side path
After doing some research, I’ve found that PathfindingService really isn’t the best tool to use for this. After doing some thinking, I realize that what I truly want are predefined nodes that are selected by an algorithm to create the best path (That is how modern GPS systems work) - Dijkstra’s Algorithm and the A* (A star) Algorithm are 2 that are most common for this.
If you have any other suggestions on the best way to go about this method, or a potential better method, I would love to hear them.
I have always been fascinated by the idea of creating a GPS system, but I haven’t really gotten around to making it. Thanks for your input, as it did really help me think through how this system should actually work.
Edit: My thoughts so far are to create a folder called “Nodes”, then have Part instances inside. Under each part will be an ObjectValue that would have the connected node as it’s Value. Each node could have multiple of these values.
Inside of a script, I would start at the selected starting node and get it’s connected nodes (through the connected node values I created). Then I would loop through each of it’s connected nodes for their connected node values, repeating the process until the final node is equal to the selected end point. Obviously this would include checks that ensure a node hasn’t already been used, etc.
I would then have I shortestPath variable, initially set to math.huge. As I loop through and create each “path”, I would keep track of how many nodes are in the path, calculating the total distance and setting it equal to the shortestPath once I reach the final node. For efficiency, if I am processing a new path and it becomes longer than the current shortestPath, I would just return and create the next path, as that path would already be too long to be counted.