Spatial grid for optimizing cave collision detection