Physics Engine
Overview
Throughout my Game Physics course, I developed my own physics engine from scratch in C# using Unity. None of the built in Unity physics components are used. I developed my own version of a rigidbody that declares and modifies acceleration and velocity. Different types of forces can be added and other features such as force generators that continuously apply forces to objects. I have implemented Oct-Tree spatial partitioning and, while I added a binary space partitioning solution, I only had time to implement it for spheres so it has been removed from the final project. I implemented spring components as well. My final project was implementing friction and resting contacts so objects lose momentum when colliding with surfaces that have a coefficient of friction lower than 1.
There are several controls to the project to showcase the features.
WASD - movement
Space - pause physics objects
T - switch collision methods (between naive collision and oct-tree spatial partitioning)
Enter - Hold to increase power and release to fire a projectile
F - switch projectile types, all but the standard cube and sphere disappear after a period of time
Left and Right Arrows - Increase/Decrease gravity in x axis
Up and Down Arrows - Increase/Decrease gravity in y axis
Page Up and Page Down - Increase/Decrease gravity in z axis
It is worth mentioning that the benefits of spatial partitioning are most obvious when there are a large amount of objects in the scene. The best way to do this is press Enter until the frame rate starts to drop, then press T to switch to Oct-Tree spatial partitioning to see the difference in performance.
As far as the UI goes, FPS is updated every half second, "Type" refers to the collision method being used, and "Checks" refers to the number of collision checks since the last time the collision method was changed, not the number of collision checks per second.
Reflection
I had a lot of fun working on this project. Many concepts I was familiar with such as velocity, acceleration, force, and other basic physics concepts, but the project also posed many challenges, space partitioning in particular. I went for two methods, binary space partitioning and oct-tree space partitioning. In the end, I did not have time to incorporate box colliders into my binary space partitioning implementation so I decided to keep my oct-tree spatial partitioning only since it performed the best of the two.
This project was made over the course of a semester so, while there is a lot of content here, there is also a lot of content missing. If I was to move forward with this project, I would want to add angular velocity and acceleration as well as support for rotated collisions.