Vehicles that follow a road network?
Asked Answered
K

2

0

It's kind of hard to describe so i'll do my best.
I am working on a kind of city builder game and one of the first mechanics I am implementing is the ability to create roads. On these roads I want the player to be able to define routes for a vehicle and allow the vehicle to pathfind along the player's road network to get to their destination. The added problem of inclines and declines is not there since the game is to be played on a flat map.

Is paths the best option? I've been looking up road networks in godot and have used paths to generate procedural roads but I cant really join these road segments together and create junctions. There is also the problem of pathfinding along these roads but that i could manage.

There is a game I like that is a good example of the kind of road making I am going for, Workers and Resources: Soviet Republic. I couldn't find a video that showcased it's road or vehicle tools so heres just the steam page

Kiele answered 22/6, 2023 at 20:57 Comment(0)
A
0

This is something I've been looking into and yes it is an absolute pain to implement and there aren't many resources I've been able to find on the methods you'd use. The path follow node is something to consider maybe but you clearly want to have the traffic interact with their surroundings a bit. The best thing I can think of at the moment is this method I've seen about where you get your vehicle controller and have it steer/accelerate based on what it 'sees' in front with multiple raycasts much like how spaceships and NPCs see in front of them with multiple raycasts and react accordingly. You seem to want something more structured and controllable though, but that's the best I've been able to find out about for the moment.

For a traffic system as an example and having the vehicles stop at traffic lights, you'd have an invisible collider for them to detect when they get near with the raycasts, enable the collider based on whether the traffic lights are red or green ( Or maybe yellow to avoid them immediately crashing 😛 ). Others may have come across other systems.

Andrade answered 22/6, 2023 at 22:12 Comment(0)
M
0

Hi, here are my thoughts on this Topic:

i would use paths but on every junction or crossing or alike i would cut the path and make independent segments. All this segements should be "joined" in some sort of junction-point. This will ultimatly give you a map of all connection of streets, this can be used as base of a a-star map. Where the junction-points are the nodes and the road segments are the node-connections. With this you can calculate pathes to every junction-point.

I think using raycasts as collision avoidance system isn'f feasable for a large scale citybuilder with hundreds of cars. If you realy want to have individual agents driving around you have to realy scale complexity down as this could kill your performance easily.
I would subdivide the segement pathes into points that can be occupied by an agent, blocking this point for any other agent. Same with traffic lights, those can block a point on the segment wich then cannot be accessed by a car anymore.

But you have to make a realy clever way to store those data. It has to be realy fast to access the appropiate points on the map. I wouldnt use object for every point on the segments because creating and accessing object in godot isn't that fast. It would be better to have some sort of structured packed arrays for all the info. They are realy fast and save substantial amount of memory.

Molder answered 24/6, 2023 at 9:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.