Profile image

[yapping] speeeeeed and poweeeeeer

115k hpgbproductions  3 days ago

Do you ever face these issues?

  • "My car gets uncontrollably fast at high speeds."
  • "I can only limit speed using maxAngularVelocity."
  • "I don't want to sacrifice low speed acceleration."

These problems are very common among car and train builders, and are caused by the difficulties of using funky trees to create realistic engine outputs. This article will not discuss any funky tree simulations, but will instead cover how engines behave in the game and in real life.

The Game

The car engine part is extremely rudimentary in its behavior. It outputs a constant torque proportional to its input, and by simply providing a basic control input to the engine, it will cause the common problems mentioned at the beginning of this article.

However, this behavior is also extremely convenient for anyone seeking to create realistic torque behavior.

Single Ratio Engine

First, study a direct drive engine (i.e., no gearbox). Torque varies with engine RPM, with different curves available:

  • Internal combustion engines provide low torque at low RPMs, before increasing to a peak at medium RPMs. The output falls off as the RPM approaches the redline.
  • Gas turbine engines have a negative linear relationship between torque and RPM. A common example is the M1 Abrams' engine, which has a torque curve that is well publicized.
  • Simple DC motors act similarly to gas turbines. The line may continue until the torque reaches zero at a "no-load speed".
  • Electric trains can have a constant torque region, followed by a constant power region. (At least, BVE train devs tend to do this.)
  • Remember that with computers, you can achieve arbitrary torque curves. However, you cannot go beyond the capabilities of your engine.

But not so fast - if you want to go the extra mile, include realistic partial throttle simulation. It is a common misconception that torque is simply interpolated between the zero and full throttle values. Instead, when plotting outputs of real engines with different throttle values, you might find that the down-ramps are roughly parallel! The same effect exists on turbines and DC motors, which will tend to displace their torque lines vertically. By replicating this feature, high-powered cars may become easier to drive, and low-powered cars will not feel sluggish when starting with low throttle.

Don't feel bad if you don't simulate it, though. I did not know of this for a long time, and many racing simulators don't have it either. (The video series by this guy also goes through some good examples of simulations, and electronic control tricks used to make high-powered cars easier to drive.)

Multi Ratio Engine

Now that you have a working engine, you can try to add a gearbox to it. A gear ratio multiplies the engine's torque, but it also can be said to "divide" the wheel speed. You can plot multiple torque curves on the same graph, scaling the y-axis by the gear ratio and the x-axis by its reciprocal. This way, you can visualize how torque varies with vehicle speed in all scenarios, and whether your gear ratios are nice (whatever that means to you) without performing a live test.

Power

But what is power, anyway? In general terms, power is the product of speed and torque. If you multiply your torque curves by an increasing straight line passing through the origin (i.e., in the form y=mx), you magically get power curves of the same height.

Note that if you do the same multiplication to the simple engine input (constant torque), the power increases linearly without stopping. Obviously, this is unrealistic. In addition, the method reveals that a reciprocal torque curve produces a constant power curve.

Now that the interactions among speed, torque, and power are well established, you will probably be trying to measure the actual output of your car. An easy method uses the concept of kinetic energy, and how it is the integral of power. Simply put, the rate of increase in kinetic energy is the output of the engine. But this direct relationship only exists if the car has no drag, nor any feature outside the engine simulation that can change the speed of the car.

The funky trees expression rate(0.5 * MASS * GS * GS) gives power in watts (Replace MASS with a value in kg). If you paid attention during calculus, and want to type fewer characters, you will be pleased to know that MASS * GS * rate(GS) works as well, but it is a crime in readable programming.

Finally, adjust the power output by multiplying the engine input by a constant to get the desired power output, and make your favorite car with 64, 280, or 1,200 PS. Remember to add drag after tuning the engine.

Conclusion

This post is very long so I will make it short:

Engine physics ez (a lot of boilerplate though)

  • Log in to leave a comment
  • Profile image
    45.4k rexzion

    @hpgbproductions i remember doing that for a go kart i made once and it freaked out one time and the kart did silly things

    2 days ago
  • Profile image

    @rexzion yeah, differential behaviors are not provided exactly so idk what i'm doing
    i've done it once (plus one more fake differential) by just using the wheel rpm difference * a constant

    3 days ago
  • Profile image
    45.4k rexzion

    it was all fun and games for me until i had to model the differential

    3 days ago