A lane change needs room
The lane graph could say that two lanes were connected. Teaching a car to move between them meant giving that connection a shape, checking the gap, and finding out that some roads had no room for it.
A lane change needs room
Part thirteen. The previous article ended with a road that could gain and lose lanes, and a driver that could not use the result properly.
The missing piece sounded small. Two lanes sit beside each other. Add a connection between them. Let the pathfinder use it. Make the car steer across.
That description skips nearly everything that makes a lane change a lane change.
A graph edge is not a manoeuvre
The road network is a graph. Lanes are connected pieces, and the pathfinder walks from one piece to the next until it reaches the destination. A normal connection happens at the end of a lane. The car finishes one curve and continues onto another.
A lane change is different. The next lane is beside the current one. Both curves continue in the same direction. The car has to leave one curve somewhere in the middle, spend some time between the two, then join the other curve.
The first version of the graph already knew that neighbouring lanes were connected. That was enough for routing, but not for motion. There was no answer to three basic questions: where does the car start moving over, how long does it take, and where does it finish?
Those answers now travel with the path. Each change has a start position, a length, an end position, and a latest point where it may finish. The driver does not discover the move one frame at a time. It receives a piece of road set aside for the whole manoeuvre.
There is a small margin before it starts and another after it finishes. The second margin matters more than it first appears. Without it, a car can complete a lane change at the exact end of a lane and immediately enter a junction or begin another change. It technically reaches the target lane, but never settles into it.
Three seconds sideways
Giving every lane change a fixed length seems reasonable until speed changes.
Move 3.5 metres sideways over a 10 metre stretch at town speed and the result may look fine. Use the same 10 metres at motorway speed and the car has to make the same sideways movement in much less time. The steering becomes sharp even though the road is straight.
The length is now based on three seconds of travel. A faster car gets more road. A slower car gets less, with minimum and maximum limits so the result stays useful at both extremes.
The sideways motion follows a smooth S-shape. It starts with no sideways rate, builds through the middle, then arrives parallel to the target lane. That avoids the visible kick produced by a straight interpolation, where the car starts moving sideways at full rate on one frame and stops just as suddenly at the other end.
There is a useful property hidden in the arithmetic. If the distance along the road grows with speed, the sideways force does not. Double the speed and the manoeuvre becomes twice as long. The car still has the same three seconds to move across. At the normal lane width, that asks for about 2.3 metres per second squared of sideways acceleration regardless of speed.
The driver also reports the lane change as a bend ahead. The speed planner can then slow down if a short piece of road squeezes the shape tighter than intended. The steering system should not be the first part of the car to learn that the planned move needs more grip than it has.
The car belongs to both lanes
Halfway through the move, which lane is the car on?
For drawing, the answer can be a point between two curves. Traffic needs a less convenient answer: both.
A car behind in the old lane still has to see it. A car behind in the new lane has to see it too. The new lane cannot accept another car into the same space just because the changing car has not reached its centre line yet.
The traffic survey therefore places a changing car on both lanes until the move is complete. Steering follows the blended curve, while spacing and gap checks treat both strips of road as occupied.
This also changed one of the measurements. The drift check used to compare every car against the centre of its current lane. A correct lane change spends most of its time away from that centre, so the check reported the feature itself as a steering error. The metric now ignores the deliberate sideways part of the move. It still checks the approach and the settled result.
Finding a gap before moving
A planned lane change is only an intention. The target lane may contain another car.
Before steering commits, the driver checks ahead and behind on that lane. The check also follows connected lane pieces, because a car five metres behind may still belong to the previous piece of the same road. Looking only at the target entity would turn every seam in the baked network into a blind spot.
When the gap is too small, the driver delays the manoeuvre. The start and finish move further along the road while the length stays the same. If a safe gap appears, the car uses the later slot. If the plan reaches its last possible start, the car slows and stops before it rather than pushing into occupied space.
I expected this check to be the difficult part. It barely fired in the town test. Across the full run, waiting for a target-lane gap happened on 721 simulation ticks. That was useful news. The large failures seen earlier were not caused by aggressive merging. They came from the shape of the road network itself.
Paint had cut the road into pieces
The last article described how a dashed lane divider becomes solid near a junction. The simulation represents that change by cutting the final 15 metres into its own lane piece. One piece has the dashed edge. The approach piece has the solid edge.
Now take a short town road with a 15 metre approach at each end. The middle can be tiny. In the failing test, 17 of 33 planned lane changes were shorter than five metres. Some had only two metres to move a full lane width sideways.
That is not a difficult lane change. It is an impossible one. The resulting cars snapped sideways with 10 to 15 metres per second squared of lateral acceleration.
The cause came from the paint work in the previous article. A visual rule had changed the pieces used by routing, and routing had assumed that every lane-change connection had enough physical room behind it.
The pathfinder now checks the available distance before accepting that connection. It reserves the full manoeuvre and the settle room. If the change does not fit, it looks for a route that stays in its lane longer. There is a fallback for destinations that truly cannot be reached any other way, but an ordinary route no longer chooses a physically impossible shortcut just because the graph says an edge exists.
Lane-change connections are also a road-network setting, off by default. The two-lane traffic scenario and the desktop studio enable them deliberately. Old presets keep their previous behaviour until they opt in. A feature that changes possible routes should not quietly alter every existing test town.
The road was part of the bug
The first broad test still looked bad after the manoeuvre itself was working. Cars left their lanes, cut corners and overlapped near junctions. I first went looking for another steering bug.
Some of that had nothing to do with the driver. Generated junction arms overlapped on the short two-lane roads. A lane curve could sit away from the centre of its own strip. Connectors used the width at one end to position both ends, even when the two lanes differed.
Those faults had been present without lane changes, but a car moving between neighbouring lanes reached the bad geometry in new ways. Fixing the driver alone could not make the result clean. The town generator needed longer spacing, junction sizes that matched the wider roads, and connector geometry centred independently at each end.
This is why the final test is a whole generated town rather than one clean pair of lanes. The isolated test proves that a car can make the move. The town proves that the roads leave room for it.
What the sweep says
The dedicated town has two lanes in each direction, 36 cars, and lane-change baking enabled. It runs across sixteen random seeds rather than one lucky layout.
Across those runs, the road network baked 7,648 lane-change connections. There were no overlaps, no lane-bound failures and no cars measured outside the road. The right-driving version recorded three cornering violations. The left-driving version recorded seven. Those are quality counts to keep working down. The hard gate, collisions and deadlocks, stayed clear.
There is an important limit on that result. It counts connections available to the pathfinder, not manoeuvres completed by cars. The desktop studio has a view for the feature: a changing car turns purple, and the selected route draws the move from its start to its join point. In practice, I have not yet caught a car using one of those connections outside a junction. There is no honest screenshot of the feature in ordinary traffic yet.
The manoeuvre works in the focused tests. The generated town can contain the connections without bringing collisions or deadlocks back. The missing proof is whether normal routes choose them and cars execute them often enough to see. That needs measurement before more work on the motion itself.
The last article ended with a road that could gain or lose a lane, and a driver that could not follow the change. The lane graph knew two side-by-side lanes were connected. To the pathfinder, that connection was just an edge. A moving car needs considerably more detail.
The path now gives every lane change a start, an end, and some clear road afterwards. Its length is based on three seconds of travel, so a faster car moves sideways over more road instead of turning harder. Steering blends between the two lane curves with a smooth S-shape. The traffic system counts the car on both lanes until the move is complete.
Before moving, the driver checks the target lane ahead and behind. If the gap is too small, it moves the planned change further along the road. If it runs out of road, it stops before the change rather than forcing its way in.
The hardest bug came from road markings. The last 15 metres before a junction are separate lane pieces because that is where a dashed line becomes solid. On short roads, the middle piece could be only a few metres long. The pathfinder tried to squeeze a full lane change into it, producing a violent sideways snap. It now rejects changes without enough room and looks for another route. Lane-change baking is also opt-in, so existing road networks do not silently change behaviour.
In a two-lane test town, sixteen traffic runs baked 7,648 lane-change connections with no overlaps or lane-bound failures. That proves the option can exist without breaking the traffic. It does not prove that ordinary routes use it often. I have not yet caught a car making one of these changes outside a junction in the desktop studio.
This is the short version. The full article has the reasoning, the numbers, and the parts that went wrong.