Physics-Based Car Mechanics
This prototype was made during my 2nd year at Futuregames for our Advanced Scripting Language course. During this project I focused mainly on the car's Finite State Machine / state pattern and designing fun car physics.
3 Weeks, Dec 2025
Technical / Systems Designer
Unity 6, C#
1 Developer
Car Physics
For this project I wanted to challenge myself to create a custom vehicle physics system with an arcade casual feel. To do this I simulated the suspension forces and the traction of each wheel with the help of raycasts instead of colliders, as Unity's Hinge Joints and Wheel Colliders are incredibly buggy and inconsistent. Raycasts provided a performant and very tweakable system that simulates the wheel physics very well. Combined with the data-driven design this allowed me to create a modular vehicle system that allows for making multiple vehicles with very distinct handling qualities without needing to write additional code. The following code snippet is of the "Wheel" class and the "WheelVariables" struct, and shows the Vector math used to calculate the wheel forces.



State Pattern
To handle player controls and movement, I used a State Pattern to more easily define custom behavior depending on the context and circumstance. The StateMachine script itself is quite simple, as all the logic is in the individual states. I modified the standard flow of State Patterns a bit for this project (or at least the way I learned State Patterns). Instead of defining all the behavior in all of the individual states, I wrote a "default" set of behaviors inside of the State Class, and when relevant the Child States override those behaviors. I did this to try and downsize the amount of work and boilerplate code I would have to write in each individual states, and because Cars generally behave in the same way most of the time. The three states that differ most with the default behaviors are the GameOverState, the AirState, and the DriftState. Making custom behavior for these states was incredibly easy, as I just had to override the methods I didn't want to use and write new logic in them.
The code snippets below are from the StateMachine class, the State class, the AirState class, and finally the PlayerCharacter class (the car).
Reflection
This project was very challenging. The Vector math used for the wheel physics required a lot of research and experimentation. I based it on springs and P.I.D controllers and other car games. The state pattern was really fun, and this project gave me lots of ideas of how I could make different state patterns for different projects.
If I were to remake this project, I would pivot more into data-oriented design, and create lots of different cars that handle differently from each other, and design extra challenge modes and make a more solid game-loop that the system could fit better inside.


