Well its been quite a while!
The 3D visual team at work has been pushing towards getting into more interactive projects. I have been leading the charge since I have always found interactive media interesting. Back in collage I took a few courses learning Macromedia’s Director and learning the Lingo scripting language that went along. Of course it turns out that I should have taken Flash and ActionScript as that became more popular during that time. I did do a couple of project presentations, for work, where I picked up Flash and ActionScript a few years ago. And now Flash is fading away as well.
On to Unity3D and picking up c#. If my current trend holds these will also be gone within four years or so. (Fingers crossed, I hope not!) I have jumped into a few projects using Unity to try and get others at work interested in the tech and see the possibilities. One thing I was not sure I could pull off but greatly wanted, if these interactive projects get off there ground here at work, would be at least a rudimentary traffic system.
I started with a simple diamond interchange, as most of our projects deal with interchanges.
The car models are part of works library of models that I had to tweak so the tires would rotate while the cars were moving.
I started off getting a car to follow a waypoint system with much help from Christopher Cherubini’s waypoint script on the unity forums. Even with the script explained in an amazing amount of detail I could get the car to go through a series of 8 waypoints, where at the end, it would then pick a random waypoint to travel to and continue randomly picking from there.
At a lan party a couple weeks ago I sat down with a programming buddy of mine, Jim Dunne, for about 12 hours straight hashing things out. First thing we did was just get the car traveling down a waypoint chain, and when it got to the end it teleported back to the beginning of the chain. From there we moved on to populating a set number of cars per chain and controlling speed limits based on passing through waypoints. The cars soon got the option to jump from one waypoint path to another. and then collision detection came into play. By about 430 am Sunday morning we came up with this.
Traffic_Sim_v.01 (Unity Player)
Sorry for the awful camera controls! I cannot recall what every bit of code that Jim did to get to this point,but this was pretty awesome.
I spent the next couple days rigging up the rest of the cars, about 33, to go in as well as figure out how to randomly generate from the stash. Each car now has head lights and tail lights attached. (have not gotten around to getting lights to work)
Traffic_Sim_v.02 (Unity Player)
Yay! Cars have a bit more randomness to color and type now! and the camera is now click to drag to look instead of stuck to mouse look.
From here I had started thinking about traffic control and getting lights to work. I took some of the waypoints and created a timer that worked like traffic lights do. Only in this instance green lights run for about 6 seconds and yellow lights for about 2.
IntersectionTest_v.01 (Unity Player)
Well I had a hard time figuring out where to go from from having the waypoints changing colors to actually getting the traffic to stop. So I ended up doing a bunch of visual upgrades to the scene. I started adding street lights and figuring out the best way to add the road grease and so on. At some point during this I had a thought that the cars detected each other, at least if there is a car in front of itself. So I had the intersection controller tell the waypoints that when they were red, they were cars. Had to do a bit more monkeying around with Jim’s drive code, but I eventually got it to a point I’m pretty happy with.
Traffic_Sim_v.03 (Unity Player)
I will probably do a bit more with this. Add to the landscape like some trees, a gas station, shopping strip. Would like to add in a night button to see how this performs with all the car lights and street lights and what not.
Any way here is the latest clean build and a few more screen shots.
Traffic_Sim_v.04 (Unity Player)
Crits \ Comments \ High Fives welcome!