itch.io is community of indie game creators and players

Devlogs

How To Exit Collider Hell

NEODRIVE
A downloadable demo for Windows, macOS, and Linux

tl;dr: things break at high speeds

This is true everywhere from physics to software development. In this case, the car would clip into the ground while taking a sharp turn. This would ruin runs on Desert Speedway and Turbine Climb, and in some cases Rock Loop I. Adding more loops for the Orange Tracks update meant the car was getting knocked off the high speed loops in a way that was unacceptable for an actual commercial product.

What was causing it, and how do you fix it? The stupidly simple fix will surprise you.

Here are some of the things I tried:

  • changing the car's rigidbody collision detection mode from discrete to continuous to continuous speculative
  • shortening the length of the physics simulation timestep
  • lowering the max depenetration velocity of overlapping colliders
  • changing the slightly pointy car mesh collider to some insane bullshit made of overlapping rounded cylinder colliders (these could get the track wall wedged in between them which looked to the player like the car clipped into the wall and got stuck)
  • hugely increasing the subdivision count of the collision mesh for the road (bad for memory and application performance)
  • making the road collision mesh a 2d surface with just the top edge instead of a full 3d object (this is why you're able to jam yourself underneath it to get that cool cut on Hydroplane)
  • adding zero-friction, zero-bounce sphere colliders slightly smaller than the wheel radius to the wheels if the suspension force wasn't working enough (bordering on the verge of insane hacks and immediately reverted)

Here's what actually fixed it:

  • quadrupling the spring strength of the car's suspension

While debugging and playtesting, I pulled up the telemetry I made when I was first writing the suspension code and realized the suspension compression ratio was peaking at a higher number than I expected on tracks where the road took a concave curve.

A suspension compression ratio of 0 means there's no compression on the car springs, and a ratio of 1 means the suspension is bottoming out. On loops, it was at 4.5. The suspension was bottoming out, and then some. And then some. The colliders I had on the car body were scraping on the road because of the weak springs and clipping into it, and then getting rejected by the fact that there were two solid objects occupying the same space, which made the car jump into the air and ruin a line.

If you think about this at all, it makes complete sense. A car taking Hot Wheels ass loops at 180 MPH will need stronger springs than a car driving at 10mph on a flat plane over speed bumps, which is all I was doing when I was setting the suspension numbers while writing/playtesting the suspension system very early on in the game's development. The issue didn't become apparent until I started making tracks that actually pushed the system to its limits.

Anyway, that fixed it. There was another issue with splines on long tracks being low-resolution so it felt like the tracks were lower-poly than they actually were, but I found and fixed it in the span of an update so you guys didn't get hit by it. Thanks for reading! I can share a writeup of my wheel code in another post if there's interest.


Why not just use Unity's wheel collider component, you ask? Multiple reasons:

  1. It's built for more realistic racing games and uses a Pacejka slip curve, which breaks my steering angle-based TCS implementation. I'm not smart enough to know how to optimize a steer angle with changing horizontal velocity and I can't do it without seeing the wheel source code, which isn't available anyway.
  2. The suspension raycasts are treated as a single vertical raycast instead of a half-moon fan of raycasts, which means that there's no gradual transition when the wheel goes over a ledge or bump. It just snaps to the distance of whatever's directly under the wheel, which looks bad at low speeds.
  3. The wheel has mass, which yanks on the connected rigidbody in weird ways.
  4. The wheels apply drive force to the ground at their contact patch, which is realistic but gets unpredictable and annoying to calculate. I add drive force from the wheels together and apply it at the center of each axle, which is way more arcadey but also allows for under/oversteer when drifting.

I might talk about my TCS code in another post, because it's kinda niche but fits well with the rest of the car dynamics I designed.

Download NEODRIVE
Read comments (4)