How can I use an input axis in an animation curve and delay how fast AnimationCurve.Evaluate works?
Hello, first of all, I'm a total noob when it comes to programing, I'm trying to make some car physics and I need to control the RPM somehow when the car is not moving. I figured I could do it just like how it basically works in real life: if you step on the gas the RPM goes up. I thought I could use an animation curve to make this happen, since I used this for the torque curve too. In theory I would set the idle RPM as the lowest value(which would mean input is 0) and max RPM as the highest value(input is 1). After that I would need to take into account engine friction and the flywheel inertia, but I'm stuck at this point. How could I control how fast or slow the RPM goes up. Time.deltaTime doesn't really work how I used it(which is simply multiplying it). Right now if I press the gas I get instant max RPM. What I have right now is:
public float input; public float idleRPM; public float maxRPM; public float currentRPM; public float torque; public float friction; public float inertia;
public AnimationCurve engineSpeed;
public AnimationCurve torqueCurve;
private void Start()
{
engineSpeed.AddKey(0, idleRPM);
engineSpeed.AddKey(1, maxRPM);
}
// Update is called once per frame
void FixedUpdate()
{
input = Input.GetAxis("Accel");
currentRPM = engineSpeed.Evaluate(input);
torque = torqueCurve.Evaluate(currentRPM);
}
Basically an on/off switch. Multiplying by anything just raises/lowers the max RPM. I can already see a big no-no with this approach, which is when going uphill the RPM should go down and in this case I don't think it will. I'll probably use the wheel RPM to calculate engine RPM while moving or a median of the two values. Anyway can anyone help me on this? or recommend another approach?
Your answer
Follow this Question
Related Questions
Making a classic animation style 0 Answers
driving up angle 0 Answers
How to get car to reverse using motorTorque/WheelColliders? 0 Answers
Why don't created animations play the way you create them to play? 0 Answers
WheelCollider RPM values all over the place, how can I get more even values? 0 Answers