Hi there, after many years of programming in different languages, I found Unity and it seems a very interesting concept. After some tries, I want to move ahead and try to create a kind of transport cargo game. I’m completely stuck with the main concept of the pathfinding of the vehicles. I’m not sure if the regular pathfinding is the “tool” I need to make the trucks/cars etc, run from the streets. Any suggestion and/pr guidance on this would be really appreciated!!
If pathfinding is the problem, you can find numerous A* systems as open source and commercial implementations.
pathfinding with vehicles, that is, you want a vehicle to navigate streets and park, is a horrendously difficult task for a beginner.
I don’t know the complexity of your job. Do you make it 2D? are you on rails? what? Without being able to express your needs with precision, you will never, ever progress. So make more effort in clearly outlining your exact needs.
Game development has always been about precise information. Otherwise nothing works.
May not be very suitable for cars. Those work better with waypoints and avoidance.
You’re diving head first into comletely new problem domain and years of programming will not help you here.So it would be best to tough it out.
Regarding pathfinding.
Rather than pathfidning what you want to look into is simple collision avoidance. I recommend to take a look at approach used in boids
https://en.wikipedia.org/wiki/Boids
As this translates to cars better than A* and standard pathfinding.
Basically your vehicles knows where it wants to go, and what things it wants to move away from, and actual movement vector will be a sum of those vector. Then your driving system should use the desired movement vector to determine where it wants to actually move and drive accordingly.
However, this applies only if you want physics based movement.
pretty easy, just set certain locations, allow cars to move there, in their own time, if collider is on at certain point, move not certain vehicles but the others (cross place…), etc, very simple…
colliders that stop cars… check, use layers to separate from certain other car types, use 2 car types…
locations, to move through and through out, or use a path layout concepts and allow to follow path and stop, but for more realism, allow to move to certain obj, on a lane perhaps using raycasts, or not, either way works, then after reaching or close to that, set another obj as its way point, very simple, but can be worked to be very complex over time… Good Luck!
edit: how come i cant like my own comment?
There are multiple layers to this.
- Destination picking. Each car needs to know where it’s going.
- Route finding. Each vehicle has to decide what roads it will take to reach its destination. A* is fine for this. From memory, when I did this I created a network of nodes in my world which represented all of the lanes on all of the roads. In addition to being used with A*, you can also include a bunch of extra data such as whether cars need to check for traffic lights or give way at particular places.
- Steering. To follow its chosen route each vehicle needs to decide which way to steer and when to accelerate, brake, reverse.
For some scenarios you could of course combine some of these, or break them down into more nuanced subsystems. For example, if it doesn’t matter where cars go then you can ignore destination picking and turn your route-finding into a simple random roll at each node.
There are a bunch of important questions I’d ask before architecting such a system:
- Do your vehicle’s travels need to make sense, or does your world just need to look populated? Or is it some of both?
- Do you want vehicles breaking road rules and such?
- Do vehicles need to use physics? If so, do they all need to use physics? (Physically simulating a whole city’s worth of vehicles at once is… expensive.)
- What kind of controls do you need with regard to how busy each road is, variations at times of day, the types of vehicle in different areas…?
- Do your vehicles need to be persistent, or is it ok if you (de)spawn them around the player or camera?
Plus one for @angrypenguin 's layered approach. There is no one system that will do this. You need a bunch of systems layered on top of each other.
I would start with getting the route finding layer sorted. A* does this brilliantly. Once you have that running, you can jump up or down layers as needed for you game.
It is actually very similar to any other pathfinding system. In a typical npc it would be:
- AI (Where do I want to go?)
- Pathfinder (here’s a path for you)
- Collision avoidance (hey, you need to keep your distance from this, this and this!)
- Actual mover(given combined desires, I should go there!)
The difference lies in step 4. In most cases, #4 will take combined vectors from pathfinder and avoidance and then using those control actual movement.
For an npc, mover would be driving the capsule or root motion.
For a, say, drone, the mover would also take care of cancelling unwanted torque/acceleration.
For a car it will also have to take care to avoid flipping over and cancelling spins.
Mind you this is not a perfect approach, and if the vehicle is physics driven, ideally pathfinder should also read data from mover, and adjust path based on physical properties of the agent.
Of course. My intent was to help get the ball rolling on splitting up a huge, non-specific problem into smaller, more specific ones. More needs to be done in that before specific decisions can be made. Gotta start somewhere, though.
use some ray casts to determine where each vehicle can move, really simple stuff
edit: i thought that was clear enough lol…
What have you tried, and how has it succeeded/failed?
If you don’t know how to even start making something that more or less works, what you need is a teacher, not advice.
Could be VR lads. We just don’t know. It could be flying cars just to spite.
Hi! thank for your note. You are absolutely right, but the lack of information in my post shows the level of frustration I have ;). Anyway, my goal is to create a simple scenario with some streets and some places around the area. Then a truck or car should go from one place to another picking stuff and carry on. To start with, this is the situation.
Thanks! I’ll give it a try and let you now!!
But here’s the thing, that’s still nowhere near the level of information people would normally need. People are guessing and you’re making affirmative noises.
Is it 3D? is it 2D? will players also be able to drive? will there be traffic management and is it 3D? regardless, if you’re seeking help, the more you give, the more you get back. Good luck though other people need my time now.