4 months ago - SDGNelson - Direct link

Notes posted alongside preview branch changelog on June 26th.

All pre-existing vehicles should continue to function normally with this update! If you find that’s not the case, I’d greatly appreciate your filing a report.

When setting out to work on vehicle physics, the first obvious problem was the huge number of vehicle variants whose only difference was color. Previously, the physics would need to be tuned on each separate vehicle variant, which was tedious and error-prone. It’s a shame that 3.0 didn’t carry over the dynamic vehicle colors from 2.0, but better late than never! I merged 149 vehicle variants down to 23, leaving us with 63 distinct vanilla vehicles to work on. This was accomplished by adding a paint color property to vehicles, and redirecting the old separate vehicle assets with new vehicle redirector assets that override the paint color. While I was at it, I added 27 spraypaint items that can be found in mechanic shops! I didn’t post any teasers about this because I didn’t want anyone thinking I wasn’t taking the vehicle improvements seriously.

Throughout working on this update I tackled a variety of smaller quality-of-life improvements. Ensuring GUIDs are supported anywhere vehicles are used, e.g., NPCVehicleReward, vendors, /vehicle command, spawning, etc. Supporting names in /give and /vehicle commands. Respawning vehicles when iterating on them with /reload. Separating the third-person camera rotation from the vehicle rotation. I tried to be thorough when writing the changelog, but I also think (and hope) there are some more improvements like these I forgot about.

Considering that wheeled vehicles are the biggest problem area, wheels seemed like a good starting point to me. One of the main causes was how bouncy the suspension was. Originally I enjoyed how much it made the cars bounce, especially after a big fall, but by comparison cars in other games hardly bounce whatsoever. I tuned down the suspension on all the vanilla cars, and added new options for the wheel models to properly follow the physics state. Previously, the wheel models rotated at an arbitrary speed, whereas now they properly account for the vehicle speed and wheel radius. It’s always bugged me how quickly the wheel models were culled, so I moved them into the vehicle’s base LOD Group, and replaced them with new slightly-higher-detail models, too.

I’d hoped to implement audio for wheels per-surface type, but this has proven surprisingly difficult to find in audio libraries online. If you know of a commercial audio library with rolling wheel sounds please let me know! For the meantime I added per-surface tire kickup particles which make driving in the dirt and grass feel more impactful. Since the ground physics material is replicated per-wheel it would be overkill to replicate by name, so the server now synchronizes a table of available physics material assets ahead of time.

Speaking of audio, the engine sounds are another big point of criticism. In particular, back in the day one friend often requested new car engine audio (among other audio improvements), and while I’m happy to have upgraded audio in a lot of areas of the game over the years, it’s always been at the back of my mind that I wish the cars sounded nicer. Researching engine audio and how it’s affected by the rising and falling engine RPM is what opened my eyes to how illogically the game was applying forces to the wheels. Teenager Nelson had somewhat arbitrarily applied a torque based on the target speed of the vehicle, and the game would cut back on this torque by 50% when exceeding max speed. Weirdly enough this kind of worked, but contributed to the halting accelerate-decelerate cycle vehicles could sometimes find themselves in. This page, Car Physics for Games by Marco Monster, from 2003 is an incredible summary of how cars are *supposed* to work, with torque varying by the gear ratio and engine RPM.

I set out to implement a realistic engine, and… quickly got overwhelmed by the complexity and worried I wouldn’t be able to accomplish it, and wondered why had I ever set out to do something outside my comfort zone.

In perhaps a case of good timing that helped clear my mind, I needed to focus on updates to the main branch (namely, 3.24.2.0, 3.24.3.0, and 3.24.3.1) and helping prepare for Escalation.

Once I got the chance to return to working on vehicles, I reminded myself to keep it simple and “eat the elephant one bite at a time.” In this case, the first step to realistic engines is for the cars to have an engine RPM and gearbox at all. I cut back to just one or two gears per car, and got each vanilla car running at approximately the same speed as it did before the update. The engine audio clip is the same as before, but uses the engine RPM (rather than speed) for pitch adjustment, which is at least a little better. Theoretically I believe the foundation is here for modders to create more realistic 5 to 6 gear engine configurations, but for the vanilla vehicles I think the next steps are to give them more realistic mass, replace the default rigidbody drag (physically incorrect) with something specific to cars, and revise all of the wheel collider friction.

That brings us to the present, plus a variety of other features and improvements! Ideally it would be fun to revamp every aspect of every vehicle type in one super exciting update, but I don’t want to hold off too long when players could at least have a better driving experience, and practically speaking the more big changes pile up the more likely it is to break a bunch of things.

Thank you to everyone who tried out this update on the preview branch before it released! Your help surely improved the stability of the update, and prevented some embarrassing mistakes on my part from slipping through. Hopefully it goes smoothly, I’ve got my fingers crossed we won’t need a 3.24.4.1 patch!