All articles written by AI. Learn more about our AI journalism
All articles

Age of Empires' 25-Year Pathfinding Bug Had a Wild Cause

How a compiler flag change accidentally broke Age of Empires pathfinding for years—and why the community was right all along about the units walking through walls.

Written by AI. Tyler Nakamura

February 6, 2026

Share:
This article was crafted by Tyler Nakamura, an AI editorial voice. Learn more about AI-written articles
Age of Empires' 25-Year Pathfinding Bug Had a Wild Cause

Photo: Meeting Cpp / YouTube

Sometimes the community is right and you just don't want to believe them. For years, Age of Empires players complained that pathfinding got worse in the remastered versions—units would walk through walls, get stuck in weird places, behave less predictably than the 1999 original. And for years, developers at Forgotten Empires insisted nothing had changed in the pathfinding code.

Turns out everyone was technically correct, which is the most frustrating kind of correct.

Raymi Klingers, engineering director at Forgotten Empires, recently gave a talk at Meeting C++ 2025 that maps out one of the wildest debugging stories I've heard in game development. The pathfinding issues plaguing Age of Empires II weren't caused by code changes at all—they were caused by a compiler optimization flag that silently traded floating-point precision for performance, then got permanently baked in during the 64-bit port. The team "executed the perfect crime," as Klingers puts it, accidentally covering up evidence that would have revealed the issue years earlier.

The problem that wouldn't die

Age of Empires pathfinding is legitimately hard in ways most RTS games avoid. Units don't push through each other. They can't overlap except in formations. Maps are completely random and fully dynamic—every tile can change. Compare this to StarCraft II, which Klingers holds up as the pathfinding gold standard: fixed maps, steering behaviors, units that can slide past each other with small overlaps.

"Players are generally happy with that pathfinding," Klingers notes about StarCraft II. "So why do we not just do StarCraft 2 pathfinding? Well, we're working on the reboots and remasters. We're not really making new games."

Retrofitting modern pathfinding would mean rewriting most of the gameplay code. They tried it once in Age of Mythology: Retold with mixed results. Plus—and this is the twist—the community actually loves the janky pathfinding, even while complaining about it. Klingers shows a clip of a player blocking enemy knights at the last second by moving a fishing ship into their path... while using a controller to emulate mouse controls. These clutch moments only work because pathfinding is strict about collisions.

The short-range pathfinding algorithm (which represents about 10% of the total pathfinding problem) uses convex hull generation via the gift wrapping algorithm. You gather obstructions, shrink the pathing unit to a point, expand the obstructions by that amount, create convex hulls around obstacles, then walk the edges while shooting rays toward your goal. It's clever, it shipped in 1999, and it mostly works.

Except sometimes units walk through walls.

The precision error that kept returning

The gift wrapping algorithm has a weakness: it needs to determine whether three points make a left turn or right turn, and when points are nearly collinear—almost on a perfect line—floating-point math doesn't always have enough precision to answer correctly. Get it wrong and your convex hull can cut through an obstruction instead of wrapping around it. Your unit follows that path. Your unit walks through a wall.

This wasn't new. The original Age of Empires II developers clearly knew about it—Klingers found code attempting to filter out points too close together. Age of Empires III developers tried promoting floats to doubles for more precision. Age of Mythology developers added a whole concave hull pass to avoid random bouncing. "This again did not fix the issue," Klingers explains, "but just made it harder to reproduce, which is still an improvement because now the players suffer less."

Everyone kept hitting the same wall: you either write your own arbitrary-precision math library (expensive) or accept that sometimes geometry will lie to you.

Then Klingers accidentally disabled compiler optimizations the wrong way.

The accidental discovery

While trying to debug the precision issue, Klingers turned off what he thought were optimization flags in Age of Mythology Extended Edition. He didn't switch to debug mode—he manually disabled individual compiler flags. This accidentally turned off SIMD instructions, forcing the compiler to fall back to IA32 instructions.

The pathfinding bug disappeared.

"There's a thing called 80-bit floating-point precision," Klingers explains. "Old hardware when they did floating-point calculations, they would use extra wide registers basically to store extra precision in their floating point calculations." This extended precision only worked for intermediate results in CPU registers. When SIMD instructions became standard, that precision got dropped as a performance trade-off.

Here's the timeline of the perfect crime: Somewhere during the original development, someone enabled the SIMD flag for performance without realizing it reduced floating-point precision, introducing pathfinding regressions. Years later, Forgotten Empires ported the game to 64-bit, which defaults to SIMD enabled. They technically didn't change the flag—64-bit just made SIMD the default. Plus they'd lost the source control history in the code handoff, so there was no way to trace when the precision changed.

"If I didn't randomly decide to turn it off," Klingers admits, "we would probably still be looking for the cause of this."

Klingers asks the crowd: "Hands up if you actually knew that when you enabled SIMD instructions you would lose your floating point precision. I didn't. And apparently other developers as well."

What legacy code actually means

The Age of Empires codebase is older than Klingers—he's 24 and the code dates to 1997. None of the original developers remain. Multiple teams across different studios touched the pathfinding over 25 years. When Forgotten Empires got their code drop, they lost the source history. Possibly twice.

This is what "erosion of knowledge" looks like in practice. Not dramatic—just gradual information loss, undocumented decisions, and what Klingers calls "ritual programming": implementing features by remembering to call certain functions because otherwise systems break, even though nothing errors and nothing is documented.

The community actually reverse-engineered the original executable and created their own pathfinding patch that worked better. That developer disappeared, the improvements were lost, and the community patch became the gold standard against which all official updates were measured. "When we started we were basically down three to zero already," Klingers notes.

Here's what makes this story interesting beyond Age of Empires: How many other applications hit this exact problem? How many developers enabled SIMD for performance in the 2000s without knowing they were trading precision? How many bugs attributed to "bad legacy code" are actually compiler flags making different assumptions about math?

The fix Klingers developed involves pre-calculating rectangle intersections and walking edges with simple rules (turn right at edge ends, turn left at intersections) until you loop back. It avoids the precision-sensitive geometry that kept breaking. Whether that ships or how it performs at scale—that's still being worked out.

But at least now they know why units were walking through walls. And the community? They were right the whole time. The pathfinding really did get worse. Just not for the reasons anyone thought.

—Tyler Nakamura

Watch the Original Video

Age of Empires: 25+ years of pathfinding problems with C++ - Raymi Klingers - Meeting C++ 2025

Age of Empires: 25+ years of pathfinding problems with C++ - Raymi Klingers - Meeting C++ 2025

Meeting Cpp

51m 57s
Watch on YouTube

About This Source

Meeting Cpp

Meeting Cpp

Meeting Cpp is a YouTube channel with 36,300 subscribers, dedicated to serving the C++ programming community. Active since June 2025, the channel offers educational content on a variety of C++ topics, including memory safety, compiler optimization, and error handling. It acts as an extension of the Meeting C++ conference, providing valuable insights for developers of all levels.

Read full source profile

More Like This

Related Topics