Torque and acceleration curve?

377 Views Asked by At

I want to have some more acceleration control over my wheel, which is just a cylinder that gets torque added.

wheel.AddTorque(wheel.transform.up * throttle);

What I actually want is to let it accelerate very quickly but at a give speed this the acceleration should quickly fall off. Like curve that starts very steep. Is there any way I can influence this using the basic .Addtorque?

Currently, my wheel just accelerates quickly to maximum velocity. Adding drag to it slows it down but I don't have the desired control over it.

1

There are 1 best solutions below

0
On BEST ANSWER

You just affect the angularVelocity property of the rigidbody directly. Just as you can affect the velocity property instead of using the .AddForce method.

Try this pseudo code

public float topSpeed;
public float decelRate;
protected bool slowDown = false;
public void Update()
{
    float speed = wheel.angularVelocity.magnitude;
    if (speed >= topSpeed) slowDown = true;
    if (slowDown)
    {
        speed -= decelRate * Time.deltaTime;
        wheel.angularVelocity = wheel.angularVelocity.normalized * speed;
    }
}

Keep in mind that magnitude calls are expensive, due to a square root function inside, though in this case i didn't see another way around it so you should be fine. Also i am not slowing it down in a set direction which is important, because this way it will slow down no matter what direction it is rotating in, or what way it is orientated.