It's not easy to do physics in games. Sometimes you hit both figurative and literal invisible walls that hamper your progress.
The Problem
I had a problem where the car would randomly crash into an invisible wall in the middle of the road. It took me several hours to solve. It turns out that the bounding box of the collider box shape that tells the physics system the simplified shape of the car for collision calculations was set too low in the vertical direction, so it sometimes touched the ground, so to speak.
Example: when turning (or braking) into a corner the simulated wheel suspension made the car rotate slightly around the local X axis, a.k.a "pitch" rotation.
This would've been fine, if the ground was mathematically a smooth continuous surface, but it's not. The collider shape for the road is made up of lots and lots of triangles. If the car collider hits the middle of a triangle, that's fine, because the surface normal vector of the triangle face is orthogonal to the surface, and thus in this case vertical.
But if it hits the edge between two triangles, the normal vector of the collision is horizontal rather than vertical, so it's like hitting a wall of zero height. Walls like that clearly don't exist in reality, but they do in the "Bullet" physics engine in Godot.
Attempted Solution
I first tried to solve it by raising the car collider box higher off the ground so that the car box collider doesn't scrape the ground when the front suspension contracts.
When/if I make a "real" track to race on, it's also going to have way fewer polygons in the racing track collider shape, because Claude created way too many, and that in itself will make this situation much less probable to happen, because there will be fewer edges to accidentally hit.
Raising the car collider box is not without its problem, however. The physics engine uses the shape and position of it in the angular inertia calculations. But I was happy with the angular inertia the way it was. Fortunately, I could override the angular inertia calculations manually and just hardcode the numbers from the previous calculations.
Back to the Drawing Board
Unfortunately, this fix didn't work. There were far fewer invisible wall incidents, but they kept happening. So, I had to try something else.
I decided that maybe the car doesn't need to be able to collide with the road to begin with. That'd solve it. The suspension is handled by raycasting into the ground and calculating forces and stuff depending on how deep the ray goes for each wheel.
But what if the car crashes and rolls over? Won't it sink through the ground? Yes, but I am instantly enabling the collision mask again if the car triggers the crashed state by running into a wall or a car at high speed.
But what if the car starts tilting sideways because one side of the car rides up on the side of the wall? Won't it at least partially sink through the ground? Well... yes.. 😑
So, I added more raycasts that always point down and keeps the car from sinking through the ground. This is working for now, but I suspect that when I add elevation and hills to the tracks, this will break again.
Update: Apparently, there's an alternative physics engine called Jolt that you can switch to, as of Godot 4.4, where internal edges are not as much of a problem. I need to give it a try.