While developing the engine it was becoming more and more apparent that I could not put off working on the physics engine. Seeing as many of the physics engines out there work for primitive objects and meshes rather than distance fields this was a little tricky to figure out.

# The Solution

After experimenting with several solutions I had a facepalm moment. I realised that as long object is in a distance field I know how far an object is from a surface. To find the point on the distance field I did a Point vs AABB check with the centre of the object vs the bounds of the distance field (Note that the distance field is broken up into chunks to drastically improve loading times). If that succeeded I would then transform the object into the distance fields local space and sample the point at that location. Once I had the point on the distance field I would treat it as a sphere and do the actual collision check.

The next part it was a bit of a problem because a distance field has no inherent shape and I needed to get a normal for collision resolution. To keep this simple for explanation purposes I will keep this to 2D and skip all optimizations. The easiest way I found was to use a kernel and sample all the points around the central point. From there I multiply the distances by the direction they are from the centre and it should give me a kernel that looks like this. After that, all I have to do is add them all together and normalize them to get the normal of the point in the distance field.

# The Next Steps

Although the current solution works it still has a few kinks in it. These kinks come from a few main issues

- The distances in the field are not perfect
- The density of the distance field is quite low
- The collision resolution is not 100% complete

To get around these I will likely have to do interpolation between multiple of the points and/or increase the density on the distance field to get smoother travel along the surface. In addition, I will have to swap out the procedural generation for something more accurate to get better accuracy (Sorry simplex noise I think this is the final hack job). My laptop is also starting to feel the strain of having no spatial partitioning at all in the engine. I think I am at the limit of brute force calculations.

Here is a preview of the changes to Erde