- Home /
I cant get lerp to work right.
This code here works perfectly but instead of the drag starting from zero to 4 it goes from 4 to zero. If i do it like : rb.drag = Mathf.Lerp(03f , 4f , 1 * Time.deltaTime); it gives a single value and it doesnt lerp
if (!(crouching && running))
{
rb.drag = 4f;
}
else if (crouching && running)
{
rb.drag = Mathf.Lerp(rb.drag, 0.3f, 1 * Time.deltaTime);
}
Comment
Best Answer
Answer by Nic13Gamer · Dec 17, 2021 at 09:33 PM
It is going from 4 to zero because rb.drag is already set to 4. You should check if rb.drag is 4 and if it is, set it to 0.
Your code should look like this:
if (!(crouching && running))
{
rb.drag = 4f;
}
else if (crouching && running)
{
if(rb.drag == 4f)
rb.drag = 0f;
rb.drag = Mathf.Lerp(rb.drag, 0.3f, 1 * Time.deltaTime);
}
Hope it helps!
Omg thank you! I changed the 0.3 in the last line to 4 and your code worked perfectly!
Your answer
Follow this Question
Related Questions
Color.Lerp is not working 2 Answers
How to lerp an object's scale? 2 Answers
Movement Script 1 Answer
Vector3.Lerp - Constant speed between distance changes 3 Answers
Doing something wrong with lerp? 1 Answer