Min and Max value?
I've been trying to create a min and max value within a min and max value but it doesn't seem to be working for me the way i would like and I'm kinda stuck with ideas on how to achieve it.
So i have a speed of my game object and when it reaches a speed of 7 the ‘ cookedAmount ‘ will = the min2 value of 0 and when the current speed reaches 10 the ‘ cookedAmount ‘ will then = the max2 value of 3. currentSpeed = 8.5, cookedAmount = 2. currentSpeed = 9.5, cookedAmount = 2.25 so on...
I’ve tried Mathf.Lerp and Mathf.Clamp and they don’t seem to work properly.
public bool overCooked;
public float cookedAmount;
public float min2 = 0;
public float max2 = 3;
(currentSpeed > 7 && currentSpeed < 10)
{
overCooked = true;
cookedAmount = Mathf.Lerp (min2, max2, currentSpeed / 11.5f);
}
attempt two,
public bool overCooked;
public float cookedAmount;
public float min2 = 0;
public float max2 = 3;
(currentSpeed > 7 && currentSpeed < 10)
{
overCooked = true;
cookedAmount = Mathf.Clamp (currentSpeed * 0.25, min2, max2);
}
Answer by doublemax · Oct 13, 2016 at 07:29 AM
This should work, i think you just forgot the "if".
if (currentSpeed > 7 && currentSpeed < 10)
{
overCooked = true;
cookedAmount = Mathf.Lerp (min2, max2, currentSpeed / 11.5f);
}
i ended up figuring it out i had to calculate the amount each value had with each other divided by its $$anonymous$$ and max.
Your answer
Follow this Question
Related Questions
Save object position after drag? 0 Answers
Mathf.Clamp does not work at all. 1 Answer
Mathf.Lerp not working. 2 Answers
Mathf.Lerp for integers 1 Answer
Int not getting rounded data 0 Answers