Before start, here's the 1st draft of a crossroad system.
This simple crossroad system contains 3 component 1. The crowd - will crossroad when the light is red(for car's driver) and will stand&wait wait when the light is green 2. Cars - will get pass when the light is green. will park and wait when the light is red. will also park when a person stands in front of it
3. Traffic Light - will switch between red/yellow/green by a timer.
Crowd Management 1. A person is spawned at the root of spawnpoint(empty gameobject). it also inherits a rotation property of the spawn point, therefore it'll face the correct direction. 2. Then we set a person's destination to a child node of the spawnpoint. If there's more than one child node then just randomly pick one. NavMesh Agent will take a person to the destination position. 3. When reaching the destination. If the destination node has no child node(considered as the final destination) then we can destroy the person from the scene. 4. But if the destination has a child node then we can move a person forward to the next child node's position. 5. if the destination node is a special command then the custom C# code will handle the person. For example, here we have a node name "waitCrossing" which triggers a person to wait for the green light from the Traffic Light object.
Cars
Each car contains two colliders. First is the car-size collider which makes user can run around. The second is a front-bump collider which works as an invisible prevent-hitting sensor. if a person (as another collider) hits this collider then the car is stopped. also if the front-bump collider hits with other car-size collider then it will stop too, causing a traffic jam.
Next thing to do:
Right now a person will reach the destination first, then turn around to match the rotation.
This can be improved by checking if persons are getting near the destination then start turning them early.
コメント