A couple of weeks back we decided we should have more going on in the background for our game project to bring the world alive a little so I was asked by the artist to make a few things move. Easy enough, I have a spline system so I just made a few objects follow those splines and job done. Well it started of like that but thought oh would be nice to have junctions and turnings, and then would be nice if they stopped at junctions and then… So it got a little out of hand and a couple of weeks later I thought I would show its current state and some of its features, hence the video below.
That has to be the most complete traffic system I’ve seen for Unity, never seen parking done before, and the overtaking is cool. I hope this joins your other assets for sale one day, I already have MegaShapes which I am guessing is the Spline system you are using here?
Ok quite impresive!
I love how smooth everything seems. The only rough thing I saw is that 90º turns seem to be made at a too high speed. I wonder how scalable this is.
Thanks. There is a system to detect bends ahead to slow cars down, some of the cars in the world have too high maxspeeds and have the overspeed value (controls how well cars stick to the speed limits) set randomly so yeah some go way too fast but easily adjusted.
It should scale with no problems, it’s a lot easier to setup roads, junctions and turnings compared to videos I have seen on other traffic systems with as much as possible automated. The CPU use for each car is around 0.01ms before threading, and as the system doesn’t use rigidbodies, colliders, wheelcolliders or raycasts there is no hidden overheads. I have yet to add culling when out of view etc. as our current project doesn’t really require it but again easily added if needed.
@MikeUpchat - Sorry, skipped over your post. Yeah it uses MegaShapes with a few extra functions. It might well become an Asset if enough people are interested, I do see a few other solutions for Traffic on the Asset Store so might not be a need for another one.
There are a few but most of them look truly painful to setup and use and seem very limited in junction types and result driving behaviour looks very unnatural so I think there would certainly be a demand for a better traffic system especially if its faster as well.
Yep I also own another traffic system, it was a bit of a pain to draw the lines add an exit lane from highway once the lane was created etc…
Just in case you need to test I could provide you with road mesh of the attached images. Its a project I’ve in the freezer sinze long ago
Crumbs that’s quite a model Don’t think I have the time to tackle that, though if there were already splines of some form defining the roads or most of them then with a little extra scripting most of the road setup could be automated.
Just for comparison this was what was asked for which only took a few minutes to put together with our MegaShapes system.
No prob.
for FUTURE I would like this to have some kind of range where the traffic occurs, as if the map is very big distant traffic is pointless or should be a curve to decimate it with distance to camera or similar LOD feature.
Splines are cool because they allow to fine tune the path yet I fear if won´t theese be too costly to compute if there are too many behind scenes, may be compute the spline only for within a distance range and the rest leave as from point to point line or simply not compute.
Would be cool to be able some kind of “traffic library” and make the lanes have specific traffic types, like left lane on Highway have noe trucks, or an industrial area have some kind of bounding voluem and define traffic within which will be mostly “industrial” like trucks etc.
I’m quite impressed this uses no raycast and physics, it looks like really does, impresive job!!
One question tho, would there be any way to interact with theese vehicles like crash into them? May be enable some collision meshes on proximity and “onCollision” add rigidbody? that would be the way? no asking to implement whole crash system, better each one add it, but just some method to “unplug”/plug" it form the trafficso it tries no longer to get back.
Can traffic detec other non traffic features such an obstacle/player objecte whatever its like a car or ped¿?
Theese are so far my ideas.
If you need an smaller patch of road based on real world road just tell me I can clip a portion of the above mesh.
editt: I think this could also be usefull for train traffic, has all the features
Each car only computes its spline position once per update and the spline interpolation is very quick, but it would be trivial to swap in a simple linear interpolation between spline knots but that will not give such nice cornering etc.
Like the traffic library concept, zones of vehicle types would be easy, and per road traffic types is already in.
The objects being moved by the system are just regular game objects so you are free to have colliders and rigidbody components attached if you want, and a simple addition in the OnCollisionEnter method for the object can be used to switch from Kinematic to non kinematic and to enable any attached wheel colliders or do what ever you need to happen.
The system already has an ‘obstacle’ system which is used by the gate and traffic light systems for example, so you can easily place an obstacle at any point on a road and the vehicles will react