Car engine and feedback torque !?

Started by
5 comments, last by ventsi 1 year, 12 months ago

Hello,

i'm developing a ray cast based vehicle drifting game in Unity engine for a while now ! The game is already playable but i have things hacked and not physically correct. I would like to make the game experience better !

  • I have a simple car engine. Torque is based on throttle and a lookup curve, also supports a friction RPM based friction. The torque is pushed to the rear wheels with equal split ( no proper differential and clutch yet ) !
  • The clutch is a simple lerping of a value from 0 to 1 based on input !

So, what i'm after:

  1. “what would be a good/better way to adjust engine RPM based on the feedback torque/rpm from drive wheels" ? I want to get e little more realistic feel of engine work… What i'm doing now is something like lerp engine RPM to match the wheels rpm over small amount of time so the dash board RPM hand doesn't just pop to match it ( when clutch is set t 1 ). Not that good !
  2. The Clutch. Can you point me to some source of Clutch implementation that i can understand how it works and how to implement it in game !

Really want to make the game experience better but i'm still learning and have not that much experience on vehicle dynamics ! Also any suggestions, sharing of knowledge, tips, some example code and such would be highly appreciated : D

Thank You in advance !

Advertisement

Start from goals and figure out what physical details are important and need a detailed simulation.

For example, if you want drifting you need a good instantaneous model of which wheels are slipping or not and what traction they provide (and therefore a good model of friction between tires and ground and of lateral forces) and if you want the player to manage drifting you need the means to represent interactive controls (special brakes, differential locking, etc.).

Regarding specifically feedback from the wheels to the engine, should it matter because there should be a risk of turning off or damaging the engine? Because different cars should behave differently? Because it has “tactical” applications (the right altered engine RPM at the right time)?

Omae Wa Mou Shindeiru

ventsi said:
I have a simple car engine. Torque is based on throttle and a lookup curve, also supports a friction RPM based friction. The torque is pushed to the rear wheels with equal split ( no proper differential and clutch yet ) !

The engine should have 2 curves, one for power and one for coasting. Look them up according to the RPM and blend them with throttle position.
eg: TorqueOut = Lerp(TorqueBrake(rpm), TorquePower(rpm), ThrottlePosition);

One of the cornerstone of drift cars is proper differential, and clutch setup. I've been dealing with a car sim for many years and still not confident if I could set up a cool drift car.

ventsi said:
The clutch is a simple lerping of a value from 0 to 1 based on input !

Yes, more or less. The clutch has a maximum torque that it can transfer, the linear input mapping can be a good starting point. The tricky part is how to handle the locking/unlocking scenario, so when the current clutch torque exceeds both engine and feedback torques it locks, but as soon as one of them overcomes this threshold it opens (starts to slip) and the engine and the rest are starting to rotate differently.
The whole drive-train works a bit differently when the clutch is unlocked. You might want to check out racer.nl there are lots of useful stuffs you can use.

I actually have the game released in early access on Steam and it's playable and enjoyable !

About the differential, i have a function that does LSD with locking coefficient and EqualSplit torque. Both work.

I struggle with engine feedback torque ! Also, not having a proper Clutch implemented as don't know how it implement one !

First and most importantly i need to improve the engine rpm adaptation to wheels rotation ( engine feedback torque )

My current code is like that (C#, but pretty much understandable)

First function is the Update function in the car controller script, dealing with getting engine torque, transferring torque to wheels etc., second function is part of the Engine class and not sure what the logic suppose to be in that second method. I am currently using a function that tries to adapt engine RPM to wheels RPM. This is important otherwise the engine just reaches the maxRPMLimit very quickly ! However my code is far from ideal even though it does some job !

I'm kinda lost with this !

// This is part of the Car Conroller component
private void Update()
{
    // other code
    
    ......

    // Getting wheels RPM on rear axle
    wheelsRPM = (GetAxles[1].wheels[0].wheelController.RPM + GetAxles[1].wheels[1].wheelController.RPM) * 0.5f;
    wheelsRPM = Mathf.Abs(wheelsRPM);

    // Multiply by transmission including final drive ratio
    wheelsRPM *= transmission.getTransmissionRatio();
    // Clamping adjusted wheels RPM to max engine RPM just in case
    float wheelsMaxRPM = engine.getLimitRpm();
    wheelsRPM = Mathf.Clamp(wheelsRPM, 0.0f, wheelsMaxRPM);

    // Adjust engne rpm based on wheels roatation
    float clutchState = car.clutchState;
    engine.SetFeedback(wheelsRPM * clutchState);
}
// This function is part of an Engine class
public void SetFeedback(float wheelsRPM)
{
    mRpm = Mathf.MoveTowards(mRpm, wheelsRPM, moveTowardsRPMMultiplier * Time.deltaTime);
    mRpm = Mathf.Clamp(mRpm, mIdleRpm, mLimitRpm);
    angularVelocity = mRpm / rads2Rpm;
}

Actually the wheel feedback torque has nothing to do with RPMs, it's coming from the road resistance (from the tire formula) and the brake torque.
If you want realistic result (this took me for a while to figure out too) you need 2 different behaviors.

  1. when the clutch is locked the engine and wheels are “physically” connected. The engine angular velocity is directly derived from the wheel angular velocity, no need for lerping or blending or such. The engine torque directly goes to the wheels and as it accelerates the engine RPM is just calculated back from the wheels.
  2. when the clutch is open, the engine is working independently from the transmission+differential+wheels

In the second case the engine torque only accelerates the engine only (!) not the wheels, and the feedback is “not going anywhere”, just acting on the wheels and directly connected parts.
BUT. There will be some angular velocity difference between the engine flywheel and the clutch at the transmission side, and that speed difference makes friction which is a torque that tries to slow the engine down and speed the transmission up. And when their speeds match the #1 behavior takes place.

At the beginning I couldn't really get my head around this part, so I made a fake drive-line “simulation”, that ended up so convincing that I used for years.
The basic idea was that the wheels and engine were always connected (except at low speed) and depending on the engine torque I just changed the wheels' current rotational speed.
Take the current free-rolling angular velocity and just increase it according to the engine torque. Easy as pie, and after some tweaking it was pretty drivable… I don't encourage you to do so, though ?

Hi, thanks for the tips !

I think i found the problem and some solution though !

I did previously clamped the wheels ang. velo. to engine's limit RPM ( ang. velo. ) which is incorrect, as if the engine is too powerful it will boost wheels ang. velo. too quickly and thus makes itself rotating too fast in short amount of time, as it looks at the wheels ang. velo. when clutch is locked. I'm now doing it like this, clamp the wheels max ang. velo. change to be same as the engine's ang. velo. plus a little more ( e.g. 0.5 - 1 radian or such ) which is not perfect solution but does some job… In the video is visible how engine now increases load a bit smoother, as in previous version it did jump to max rpm quite faster !

I just guess that there should be some way to say the engine that there is some max allowed change in angular velocity per frame !

This topic is closed to new replies.

Advertisement