← Home

The new car system

25 October, 2024

Something I really wanted to improve on in Broadview was how cars drove. While I still think it was okay, it might help to explain how cars worked in V1 to understand why I made the changes I did.

In V1, each car had a table of gears, and associated with each one was three values: the car's velocity, acceleration, and torque, all applied to each wheel. For example, here's the Patriot's gear table:

GearVelocityAccelerationTorque
11815110000
2411280000
358940000
479630000
592415000

So there's a couple of problems here. First of all, why the hell is the torque so high? We'll get to that in a second. Second, this isn't even close to how cars work. In real life, cars have a torque curve, which is a graph of how much torque the engine produces at a given RPM. Here's an example of the torque curve of a 1997 Ford Crown Victoria, analogous to the "Frontier Liberty" in Broadview.

So, we need to somehow translate this to a game. The first step is to reconsider the physics constraints that we're using. In V1, we used CylindricalConstraints to both turn and drive the wheels, whose properties correspond to the gear table above. But like I said, there's no way to figure out what velocity or acceleration to set these constraints to in order to drive the wheels. So, I decided to switch to the dead simple Torque constraint. All it does is apply a constant torque to each wheel.

But what is the torque? Well, it's calculated from the engine's torque curve, but we need the RPM first. The RPM is calculated from the car wheels' velocities. and the current gear ratio. The torque is then calculated from the engine's torque curve at that RPM, as well as the current gear ratio. The torque is then applied to the wheels! The math to do this isn't actually that complicated. Unfortunately though, this doesn't account for free revving the engine-so we have to fake that. I'm not entirely sure how racing games do this, but I simply increase the RPM while the throttle is pressed and decrease it when it's not. It's not great, but it works.

Well, now we have a problem. The cars don't move! Remember how the torque values were insanely high before? Well... that's because, in real world units, the cars actually weighed tens of thousands of pounds. Nobody really noticed this because the cars had enough torque to move them, but now that we're using real world units, the cars are too heavy. So, I had to reduce the weight of the cars by adjusting the density. Each car now has a weight that directly corresponds to its real world values. The Patriot, for example, now weighs around 4000 pounds. I also had to adjust the suspension springs to account for the new weight.

So, I've went ahead and applied realistic (or close enough, if I couldn't find good data) torque curves, gear ratios, and weights to all of the cars. Now it's time to hook up the UI! Well, we need a new one, because we need a tachometer now.

The new car UI

The new car UI

Something to note: The miles per hour calculation has changed. It's now actually based on Roblox's physics unit conversions, so it should be more accurate.

There's still work to be done with the new car driving. As I mentioned before, the free revving is pretty bad, and cars also don't accelerate off the dig as fast as I'd like. Some cars' first gear extends for too long. We also don't have any new engine sounds yet, but I think that'll come soon. But here's a video of it in action! I drive a couple of different cars in the video to demonstrate it.

Me driving the new Rancher and a Python

Sorry if the video's washed out. Still working on how to record in HDR.

Hope you enjoy and more to come!