- Home /
making a traffic system
I have a city roadmap, and i was wondering: how do I make a simple traffic system where cars stop at lights etc?
This is probly something you could break down to smaller questions.I would also think its a little vague.
Answer by twinnightmare · Jun 27, 2010 at 06:37 PM
On the light stopping part I would direct you to using triggers, Specifically OnTriggerEnter to detect when object reach's a light. and OnTriggerStay to update weather the object need's to keep stopped or proceed. Collider class
[Edited 1] Way-points would work for a system of paths with cars following them like your wanting.
and how about getting the cars to stay on their side of the road and moving the cars aswell, would waypoints work?
That's a trick job, but yeah, waypoints should work. You would need to put the movement script inside an if trigger to be disabled at lights. Create a trigger that makes the car stop at lights by calling the if statement.
Genius, but maybe not disable the script, but get the car to apply the brakes, otherwise it will just keep rolling forward? Or is there away to get it to slow down if it's in the light trigger object?
See the question on would it keep rolling forward depends on how your moving your car's? The way i would do it is your car would have a script with a variable bool stopped; when your car enters the light's trigger you set the cars to stopped to true if the light is red, then in the OnTriggerStay you would check if the light was green if it is then set the car stopped to false. Then in the update part you would check weather the car is stopped if it is then you would not move.
Answer by Kethis Celebes · Jun 28, 2010 at 12:53 AM
There are agent-driven traffic simulations which Civil(?) Engineers use. Try looking into those, to see what tricks they use.
Your answer
Follow this Question
Related Questions
How to create a system of damage to a racing game 1 Answer
Roads and traffics system Made my system extremely slow 0 Answers
Accessing local system ( File Browser ) 2 Answers
Finding center and/or lanes of road mesh 0 Answers
Pathfinding with Roads 2 Answers