3D Collisions and Resolution
This isn't ready yet, but when its done it'll be a brief rundown on computing 3D collisions with code examples.
Learn moreA 3D Physics Engine with a focus on education
In early 2024 as a part of an assignment for class we were tasked with creating a 2D physics engine, complete with polygon, plane, and circle collisions, and rigid bodies. (be that with Euler or Verlet integration)
As an extended challenge for myself, I set the task of also adding rotational collision resolution and gravitational forces.
With that securely under my belt, when then given a new assignment on creating a complex games system, I decided to try and make a 3D physics engine, except this time I wanted more than just rotation, I set my sights on friction and contact forces too!
3D physics had always seemed like a pipe dream, but physics has always been a passion of mine, both as a student and teacher. A big struggle of the research for this project was that there is nearly no open source discourse on solving 3D collisions, this lack of content though instilled me with a new goal, if I was going to crack 3D collision, I would also need to make the work I had done readable, and accessible for people who also want to take these steps themselves.
This assignment instead spanned for 5 weeks, and also needed to be a C++ library. This was actually the hardest programming task I had ever set myself and I was yet to find out.
I began by taking some basic ECS code to unity to help myself emulate my C++ workspace but with some useful tools I could use for visualising.
Approaching the physics I decided to tackle each step of the collision phase one learning step at a time.
1. Collision Detection:
In 2D I had originally done collision detection using Separating Axis Theorem (SAT), SAT stepped through each edge, and each vert on the two colliding polygon's and determines the axis of separation, however for 3D you also need to add faces to the cycle, and I wasn't looking forward to an additional pass and then also determining the point of collision for rotation, so instead I decided to use Gilbert-Johnson-Keerthi algorithm(GJK), GJK instead uses a point cloud of vertices and subtracts every vert from the other collider to determine whether 0,0,0 is within its bounds. This process is similar to comparing two numbers, if you subtract one from the other they are the same if the result is 0. GJK was rather fun and I was able to learn what I needed from resources like these from Kenton Hamluik and Iggmonclar. GJK also allowed me to use a radius with my colliders, here is my testing my work on unity.
The engine isn't perfect, but for setting aside this idea for a 5 week task I am so happy with the results. I will get back to it soon, but for now I will bath in the glory of its shiny bloomy self.
I'm working on a presentation about the step by step breakdown of 3D physics, however with the ending of university its been harder to find the time to get it in a good state. It'll be out soon.
This isn't ready yet, but when its done it'll be a brief rundown on computing 3D collisions with code examples.
Learn more