Increasing physic engine speed. Can work with more than just Godot

How to give Godot and super increase in speed in the physics engine. First I will explain the problem Godot has, as do all physics engines at the time of writing this. Then, I will explain a solution to the problem.

Right now Godot’s physics engine tests each object against every object in the scene. The more objects in the scene, the slower it goes when moving something. I know a way to test those moved objects only with what is close to them. Nothing else gets scanned or checked.

A grid. Let me explain each part of this thing. The grid has four corners. Each corner is represented by 4 vertices. This says where the grid is placed in 3d space. Each grid has a list of objects. The objects the grid lists are the one’s in the same space. This way, when an object moves, it is only tested with what’s listed in the grid it occupies. An object can occupy more than one grid.

Now, it would be slow to test the bounding box the object to see what grids it falls into. But I know how to do direct memory mapping for that grid.

Lets go back to the grid. The grid is a perfect size, of (10,10,10). That is how big one grid block is. We will use an imaginary space of 100,100,100 grid blocks. That covers a huge area, and there is many of them. Now, we will take an array of pointers, array[100,100,100]. This array of pointers point to each grid block. To find the direct mapping for that array, you take the vertice and do division on it. Lets say the vertice is at (82.5,82.5,82.5) cordinate. 82.5/10=8.25. This means it occupies grid (8,8,8). Straight to the grid. You only remove the decimal. This is easy with, int = float;

The idea is to reduce the amount of calculations being done, by only doing them on what might be needed.

I don’t have a name for it. Has this been done before?

What you’re describing sounds largely like a spatial hash grid.

This is an engine agnostic approach to fast proximity checking of lots of objects and is generally useful for things like crowds, boids etc. but is more rigid/limited than some other approaches. I thought there used to be an add-on for this, but maybe not in 4.x. It’s also pretty trivial to implement yourself so an add-on is probably overkill.

However, I can pretty much guarantee that this and/or other tech will already be at play in the backend of any physics engines (likely Bounding Volume Hierarchies), so for raw physics simulations this or something faster/more dynamic should already be present.

Right now Godot’s physics engine tests each object against every object in the scene. The more objects in the scene, the slower it goes when moving something.

It’s more about how many ‘active’ objects there are, not the total count. Can easily see this in my Potato Physics video where a stack of Potatoes gets laggy around ~3,000 but space them out and it’ll handle 10s of thousands.

1 Like