Victor's Devblog

If you are interested to receive those weekly articles as a newsletter, poke me offline! Automated subscription is disabled because of bots...

Otherwise, Atom feed is here!

Improved Car Control

Another slow week.

Energy conservation

First I started improving energy conservation. The issue encountered last week was that slipping wheels on slippery surfaces would accumulate speed and then suddenly provide a lot of energy to the car the moment surface was not slippery.

The solution I went for consists in correctly laying down the constraints of the system: player's input provide energy to what I will call the "engine block" (which includes the wheels and has a given inertia) then the engine block trades energy with the car's chassis through friction of the wheels with the ground. This correctly done in code, energy is now correctly transferred and car doesn't suddenly gain energy as it goes from ice to asphalt (skid marks are there to understand how car turns, not really related to drifting YET):

Drifting

Second I wanted to introduce some drifting mechanic, for the purpose of making driving more interesting. Ideally there would be situation where properly drifting would allow better or tighter turn in racing context.

Since driving is already done through friction (usually quite high so that car's wheels don't slip unnecessarily), the idea I got (probably not new) was to introduce two regimes: first a normal regime where relative speed of tire's point of contact with ground is slow enough, so car just "rolls" without sliding (= static friction), then a regime where, if that relative speed goes above a threshold, wheel starts sliding (through some sort of dynamic friction that doesn't completely cancel that relative speed). Adding some hysteresis was also a good way to make drifting more enjoyable, helping the car stay in a drift for longer (still very much WIP).

Notice the bad transition from ice to asphalt.

Sliding

Ok, playing with the various static and dynamic friction coefficients was nice, but it became evident that the junction of low friction surfaces with high friction surface was .. odd? Since low friction surfaces would probably be some sort of icy surface, I started exploring a different kind of logic, using a lower static friction (so proportional to wheel's relative speed with ground, but not completely cancelling it) with also a mechanism that freezes the wheels and makes them lose grip for longer even after leaving the icy road. This is even more WIP, but here it is:

Notice the improved transition from ice to asphalt.

CMake

Final update of the week which kinda stalled development for a while: I went down the rabbit hole of reorganizing my project using CMake and correctly splitting engine code from code that belongs to the driving game I am working on.

Here is this week's only blooper, no input but wrong tire friction computation that made the car go Beyblade!