Most of my development was inspired by small Flash games and a recent university assignment which had me and my colleagues build and code a self-driving remote control car, in which we needed ways to test multiple setups for its AI system, and as such needed a simulator to see how certain parameters affect handling.
The simulator was simple, but it allowed to check for differences in road conditions ( slippery vs. grippy, which was done by covering the track with soapy water ), and helped a lot with tuning the stering angles and required power curve of the car, whose electric motor was powerful enough to reach 80+ km/h.
Fortunately, we did not have to gear down the motor with special parts.
After that, I started to port the simulator to Unity, and make it complex enough to be fun and close enough to reality for a game.
So far, the suspension, and it's direct involvement in steering is not yet implemented, as I am still working on how the tire interacts with the car and the ground. Most of my knowledge on this subject is from the following paper: Car Physics for Games ( 2003 ) and Race Car Vehicle Dynamics ( 1994 ) .
One important fact I want to mention is that, before starting this project, I had assumed that the wheels of a car are always rolling, with a contact patch that has an instantaneous velocity of 0 in relation to the ground, even under acceleration, but my intuition was obviously wrong, as wheels produce the reaction force which pushes the car forward by friction, and as such need to be spinning at an ever so slightly higher speed to produce force.
One big part in this game's design language was this video that I found on Youtube: MECHA - YOUTUBE , which had this gorgeous timer ticking down, which I unceremoniously remade in my game, and placed it front and center as counter for the lap time and current time.
It's implemented as a Canvas Component, with individually addressable segments, and an optional driver to have it display numbers using said segements, but could be expanded to display letters too, functionality which was not needed for this project.
Each letter has different segments lit up, and as such, I also made a nifty tool to help with that, so creating the individual states was easy to do.
So far the play testers like it, and if everything goes well with the project, I will make it available as a standalone package.
Another big milestone was the finish line, which had to be able to detect when the car crossed it, and most importantly, it's direction. The first part is trivial, but because the car is not a infinitezim.ally small point in space, I used a raycast ( which is not unlike a laser range finder ) to detect when the car passed the finish line.
The big problem was dealing with the direction the car is travelling, as the first method does cannot deal with the car driving past the line with it's front, and then reversing before it fully passed the line, manouver which could skip the entire track, timing-wise.
As such, I tried several ways to solve this problem, using two lasers, trigger boxes, and delays, but they each had their flaw, mostly timing accuracy, all adding to the time the car actually passed the line, increasing the lap times for the players for no good reason. When you pass the finish line, you expect the timer to stop, right?
Finally, the solution was to record the Dot product of the car versus the normal of the finish line while it passed the finish line, and saving it after it leaves it. When it passes again, if the end dot product differ, it means it has passed the line without turning back, and the sign of either one of them determines the direction.
Wheels, in their most simple conceptual form, are objects with anisotropic drag, lower along it's rolling axis, and higher on it's perpendicular axis. The fact that it rolls is simply just the natural consequence of this fact, and also adds the benefit of even wear along said axis.
At first I didn't even model it's rotation, but issues with how it's displayed and the lack of torque inertia made it very jarring for the players, and I remade the system to include it.
After struggling a bit on my own, I started reading papers on the subject and implemented them into my project, which proved to be a very fruitful way to improve it dramatically
This screenshot was taken during one of the early tests of the new wheel module. The display lines are smeared down, to act as graphing paper, and the wheel is spun at various speeds, with varying grip settings.
Because of how the power delivery system was implemented at the time, it can be observed that the wheel spins at a constant speed when it reaches it's maximum grip load.
The trace is made by a point at one of the corners of the block that depicts the wheel
The most important part was how the relative speed to the ground affects the wheel and it's rotational velocity, which was achieved using a grip slip ratio curve, as detailed in the Car Physics for Games paper. By tweaking this graph, wheels can be taylor made for various applications, like very easy to spin out wheels for drifts or very grippy wheels for dragsters
A big part of how the car handles is it 's acceleration, and how that changes with the RPM of the engine. For pragamtic reasons, the engine is not simulated, and a simple power curve is enough to emulate it convincingly.
The power is delivered to the individual wheels via connectors, which can serve more than two wheels, allowing for differentials to be installed, and also serve as a way to pool the forces acting on the car, which, if applied sequentially, can result in a bias towards the side that gets processed last, as small errors accumulate and make the system unstable.
The wheels are not controlled individually by the main controller, which instead exposes endpoints for the wheels to receive the player input, and individually address them, configured by each wheel's parameters, which are, as of now, Steering Authority and Force Authority, which govern how it responds to steering wheel, break and acceleration inputs.
Because of that, it is easy to configure vehicles to have multiple wheels, rear wheels that counter turn for tighter circling radii, or offset wheels for omnidirectional travel.