-
Notifications
You must be signed in to change notification settings - Fork 7
Spatial Grid
The spatial grid is a performance optimization tool used by the physics engine (defined in engine/physics.py).
It divides the 3D game world into a series of uniform mathematical buckets or "cells."
The grid can be viewed (during Play Mode) using the console command: sg
Instead of performing a "narrow-phase" collision check between every single object in the scene—which would be computationally expensive (O(N^2))—the engine uses the grid for a "broad-phase" check. It only calculates collisions for objects that occupy the same or adjacent grid cells.
-
Grid Size: The dimensions of each cell are generally defined in
engine/constants.py -
Dynamic Updates: As entities move, they are removed from their old cell and registered into a new one. Toggling sg allows you to verify that these updates are happening correctly and that objects aren't "leaking" out of the partitioning system.
-
Command Registration: In
editor/console_commands.py, the command is mapped to thetoggle_spatial_gridmethod, which interacts directly with the Physics class.