top of page

Space Flight Simulator:
Physics System + Custom Math Library

While this is a slightly dated project from 2nd Year, it is still one of my highest graded pieces. In this artefact, I created a Space Flight Simulator that follows the laws of Newtonian physics without using Unity's built-in physics system or math library.

This project was developed in Unity, programmed with C#.

SFS.mp4
00:00/00:00

To achieve the physics of the ship, I was required to create my own maths library that performed the equations of their Unity equivalent. In the ship's movement script, I used these equations to construct a Newtonian physics-like behaviour for the ship.

 

As for the ship, its velocity and rotation are broken down into separate float variables; e.g., rotation variables include an angle, acceleration, max speed, force, and deceleration. Player input is used to adjust the acceleration values of the rotation axis using the F = ma formula, where f = player input and m = the mass of the ship. The acceleration is then added to the corresponding rotation axis angle float variable. Once all rotation angles have been updated, quaternion multiplication is used combine the angles into a single quaternion that can be applied to the ship. 

The velocity of the ship uses the same F = ma formula, except it uses vectors instead of float variables to store the force and acceleration. The acceleration is then added to the velocity vector. If the ship is not moving at max velocity, it is added directly. If the ship is at max velocity, it lerps its velocity toward the normalised acceleration multiplied by the max velocity to maintain smooth movement.

Code for Ship: Assets - Scripts - Gameplay - ShipMovement

Code for Maths Lib: Assets - Scripts - MyMathScripts

bottom of page