changing rpm when shifting
I am making a 2d racing game. The problem i ran into is when im shifting up i want the rpm to change. So that when i shift up i can say: "engineRpm -= 3000;". And it does do that, but for only one "update sequence". When the next "update sequence" is called it instantly jumps back to what it was before. I thought lerping was the answer, that the rpm would slowly build up from when i shifted. But as i said that was not the case. Any ideas on how i can fix this? Thanks in advance! Here's my code in C#:
// lerping the rpm in FixedUpdate().
engineRpm = Mathf.Lerp(0, Input.GetAxis("Vertical") * 8000, 2);
That is used in FixedUpdate() (if that helps you to know)
// changing gears in regular Update().
void Gears()
{
if (Input.GetKeyDown(KeyCode.E))
{
gearNum++;
engineRpm -= 3000;
StartCoroutine(DragTime());
}
if (Input.GetKeyDown(KeyCode.Q))
{
gearNum--;
}
}
And that one in regular Update(). Btw: DragTime is just to slow the car down for a bit to make it more realistic.
Answer by Loffen7 · Nov 19, 2020 at 03:04 PM
Just found a solution to this! I replaced:
engineRpm = Mathf.Lerp(0, Input.GetAxis("Vertical") * 8000, 2);
With:
engineRpm = Mathf.Lerp(engineRpm, Input.GetAxis("Vertical") * 8000, Time.deltaTime / gearNum);
Your answer
Follow this Question
Related Questions
Progressive lerp?? (reupload) 0 Answers
How to fix this? C# 1 Answer
unity 5 car tutorial 3D 1 Answer
simple car drift system 0 Answers
Problem in steering with wheelcolliders 0 Answers