Last time, I fell in love with Hermite curves. Since then, I’ve added a lot of new stuff. This video gives a pretty good overview of how it all hangs together right now (video captured using this technique):
That video’s a little out of date: its cars are just randomly choosing a fork in the road at each intersection. The current build has cars that route-find from an entry to an exit, so that (for example) the redundant loop at the top-right never gets used in the current build. One side-effect is that in the current build, no matter how fast I click to add cars, I just can’t achieve total gridlock. Even that is kind of a fun game, which is confidence-inspiring…
Features added since last time
- Road segments are now properly joined up into a road network!
- Road segments are one-way.
- The end of a road segment joins to the start of zero or more other road segments.
- Cars!
- Cars have a random max speed.
- Cars try not to crash into each other.
- Cars that are being held up by a car in front are red; cars that are going flat out are white.
- When you click, a car is spawned randomly at one of the “source” points (i.e. a road segment not fed by any other segments).
- When a car is spawned, it randomly chooses a destination from the “sink” points (i.e. a road segment that doesn’t feed any other segment)
- Cars use A* route-finding to plan a route to that destination.
What’s working well
- It looks fun. It’s not a game yet, but I do want to play it. This is key, I feel :-).
- Not much code yet, but I’ve solved a lot of the difficult problems already. The geometry of curves has worked a lot better, and is a lot more cleanly implemented, than I would have guessed.
What’s not working well
Argh. Visual design conflict.
On the one hand, I want the road network to be abstractly beautiful. At the most basic level, the game’s going to reward the player for making traffic flow smoothly. In addition to the game rewarding the player directly, there’s also an aesthetic kick to arranging a network that runs smoothly (think about a perfect four-platform-station coal mine to power station route in Transport Tycoon Deluxe, say (more info here). Oh god. Oh yeah. That’s the stuff, right there. Oh boy.). More than that, I want there to be another aesthetic kick just because the shape of the network is itself beautiful, even apart from its (imaginary :-)) function.
But on the other hand, I want the cars themselves to be cute. To make the game a bit more hormone-driven and a bit-less grey and minimalist and intellectualised. Maybe inspire empathy. Think of the dots in the video above getting more and more jittery in a cute expression of frustration as they’re stuck in gridlock. It’s pretty easy to achieve – I’m already starting to feel sorry for the little guys when they get stuck, and I’ve invested basically zero effort in visual design so far.
If I get the job done, I’ll be able to deploy tactical cute to take advantage of its visceral, crack-like hook when drawing players in, and then gradually reveal the majesty and scope of a city-powering spaghetti nightmare intersection as they progress through the levels.
Upcoming decisions
How to model multi-lane roads
Broadly speaking, I can see two approaches. Imagine a gently curved four lane highway, with two lanes in each direction.
The first approach is simple: every lane is modelled as its own curve, with its own start and end points and tangents: in our example, we’d have four separate curves, one for each lane of the highway segment.
Another approach is to model just one curve, the centreline of the highway. Then, the various lanes are on either side of the centreline. To find a point on the leftmost lane, say, you choose a point on the highway’s centreline, then move two lane widths along a line perpendicular to the highway at that point. To find the corresponding point on the rightmost lane, you’d move in the opposite direction along the same line.
I can see pros and cons of the two approaches, but I haven’t thought things through enough to make a firm decision yet. The second approach has appealing simplicity - think about tweaking the start and end points of a single curve rather than four “parallel” curves. But how much complexity will that add elsewhere? If a sliplane comes off the left-most lane of a four lane vertical highway, then joins a six-lane horizontal highway, then how and where do we store the “connectivity” between the segments? Do we say “lane –2 of the four lane highway connects to lane –1 (the only lane) of the one lane sliplane, which in turn connects to lane –3 of the six lane highway”? It’s conceivable, but I’m not sure it’s simple :-). Of course, I’m happy to take an internal complexity hit so long as there’s no easy alternative and I can find an intuitive way for the user to manipulate the road network layout. With some basic (and common-sense) rules (e.g. sliplanes can only come of or join the outermost lane of a highway), I think this could be made to work.
How to model intersections
The sim currently doesn’t know about T or four-way (six-way?! eight-way?! milliways!?) junctions. Should it? Could I come up with a fun design without the complexity of traffic lights? Assuming I did, would the lack of controlled intersections be a reality niggle in the player’s mind? What about the developer’s? :-)
To do (short term)
- Cars look “sideways” as well as forwards, so that they merge cautiously and safely.
- Model vehicle arrivals using a Poisson distribution vehicles so my mouse button doesn’t wear out
- Multi-lane roads
To do (long term)
- Cars slow down according to the tightness of a curve
- Make the network interactively editable
- Cross-overs (either a 2d-fudge or genuine 3d)
- 3d display engine rewrite (i.e. make it beautiful)