Remember in Futurama where there were flying cars that flew along a path?
I want to do this.
I have a series of gameobjects, I give the cars all a list of nodes (empties) to fly at, then here is what I want.
spawn at node 0
orient toward the next node using rigidbody and applying rotational force (physics).
if we’re pointing at the next node, apply force toward it
If other vehicles are blocking, go slower to avoid collisions
When within range of the next node, increment the target node from the list and start reorienting toward that node.
Various vehicles have different masses, so they can create slowdowns.
Here’s what I’m having trouble with:
My vehicle factory can spawn cars, but I don’t know how to pass in a list of nodes, and other rigidbody variables.
I know there is a way to do the flight stuff using physics, but not finding it in the search. This is essentially zero gravity space flight. we’re assuming hovercars here.
Woah… that’s a lot. Maybe you should create a separate question for each part? In each thread you could link to this question so people can read what the final result should be.
Topics (not necessarily question titles):
- Node path management
- Wait for the Rigidbody to face towards the destination before adding force forward (do you really need physics, though?)
- Detect obstacles and slow down if needed
Let’s turn this line of thinking around a little:
Rather than worrying about making each car completely autonomous, decide from the start which path the car’s going to follow instead. You can do this by creating a controller for the nodes.
Your “Vehicle Factory” asks the node controller for the path to send the car along (i.e. a List). Once it has a proper path planned, it double-checks that the spawn point is clear (such as Physics.OverlapSphere), spawns a new car when able, then passes the List to a script on the new car.
To detect being near a node, each node can potentially have a “Trigger” collider to send a message to cars as they arrive. If that node is their current destination, change to the next node in the list.
Finally, to have each car avoid each other, each car could have a (one or more) trigger collider child to alert any other nearby cars that they’re encroaching on a car in front of them.