I made a post on here a little while ago explaining how I set up the suspension for the game but I spent the last month completely rewriting it.
Happy to answer questions here but I'll give a brief explanation of how I set it up.
With the game I'm making I have a roguelite upgrade system so it has to be fast and modular, players can upgrade bumpers, engines, suspension, wheel/tyres, and their winch.
- Each suspension top has an array of Vector3 for raycast offsets that pass out averaged hit normal, raw hit normal, compression, averaged hit point, wheel centre (depending on tyre size) and terrain layer for grip amount. (Tall yellow lines from the suspension tops)
- Each raycast gets the hit angle and compares it to the wheel centre so I can simulate 'round' tyres (the front rays will push back while the rear rays will push forwards) (these are the fine yellow/red lines pointing down from the suspension points).
- A method for longitudinal force, which primarily uses the smoothed hit normal and grip levels. It's just the player input force applied to the wheel centre. (Blue lines)
- A method for lateral grip levels which run mainly off grip layer, raw hit normal, and a bunch of animation curves that check against axle speed (thicker Red lines on wheel centre)
- A whole other method for handling wheel spin that runs after the main methods, this took ages to code but feels soooo good, it runs after so on the next frame I can pass in slip and spin values to the lat/long methods (You can also now do sweet burnouts)
- The final piece was lateral impact forces (the small grey lines), they handle any sidewall impact on the wheels and tyres, this one runs separately to the rest but takes in lateral speed and tyre spin to cause damage to the suspension or wheels.
Thanks for reading!