[Feature Request] Physics LOD

It would be nice to have Physics tick processing have an LOD falloff.

When dealing with 1000 Bots the capsule physics calculation can dominate the per-tick processing.

As Bots get further away there are several reasons you can process less:

  • The angular movement of the bot relative to the player’s screen is very low, so processing to the millimeter is not needed for apparent smooth motion.
  • The accurate position of the bot is not required because the player can not tell if the bot is exactly touching an object or simply is very close.
  • The attention of the player is on the nearer bots that are a threat.

So the way this is implemented is that as the bot gets further away the capsule update only happends every N ticks and inbetween you lerp the position for smoothness, but even the lerp time step can be LOD’d and it will be visually smooth.

(Related but not part of the system: The graphics LOD decimates the polys in several steps down to a billboard sillouette.)

There are three ways to throttle this:

  • By distance from the player
  • By count of bots by distance, in other words the nearest 10 get every-tick processing, the next 10 get every other tick processing, etc.
  • By millisecond quota of CPU time per tick.

Implementing any one or a few of these techniques will result in a huge gain in performance.

Another refinement is to have a bounding box or sphere on geometry. If the bot is on terrain and no other colliders are near (e.g. within 4 meters), the capsule can be ignored and just use terrain altitude calculation. The same grid of moveables can be used for proximity checking and avoidance of other bots. This lets large mobs in open world games be ultra efficient.

We did an implementation of this in Unity and it requires some infrastructure.

  • A grid over the world of about 4 meter square bins that have all moveables in that area in them.
  • Bounding boxes on buildings.
  • A progressive scan dictionary. (A dictionary with 100 sub-dictionaries so you can iterate 1% at a tick)
  • A list per player of zombies in roughly distance order, using the progessive scan dictionary.

Note that the distance sorting can be very approximate, but more accurate near the player. The sorting decisions can be LOD’d too. Thus you LOD the LOD decision. Also the ‘in bulding bounding box’ decision can be lazy because you only have to detect it soon enough, not necessarily accurately.

Also when we implemented this we removed the capsule from the Bot and instead used a capsule sweep test to check for obstacles. This gave us exact control over the PhysX processing load. Most movement was just a terrain altitude check, and a current building bounding box occasional check, and if in a building, a capsule sweep check.

This approach lets you have 1000 Bots, all fluid and well balanced, and every single one is an independent NPC AI and Physics.

Both this feature request, and “[Feature Request] AI LOD” use the same approximate distance to player tracking infrastructure.