- Home /
Animation Curve to Float variable? help!
Hello, I'm trying to make a float variable follow a specific pattern, and the animation curve serves me a lot, but I can't get it to follow this pattern (I'm simulating a gearshift effect with different tones).
Thank you!
//EngineRPM is a float
//ShiftingCurve is a animation curve
EngineRPM = ShiftingCurve;
Answer by The_Three_Vs · Aug 20, 2020 at 07:10 PM
Is the animation already configured in the pattern you want? To get the value out of an AnimationCurve you need to use ShiftingCurve.Evaluate(t)
, where t
is the x-value you want to get the curve value of.
Yes, it's a V-shaped curve (go down and up at the end)
And when using ".Evaluate (Time.time)", it does not work, that is, the float value does not go down and go up as in the curve.
EngineRP$$anonymous$$ = ShiftingCurve.Evaluate(Time.time);
In your curve, is there a gray line on either side? Since Time.time is an always-increasing value, in order for the curve to return changing values the right side of the curve must be set to "Loop".
Exactly !, I put it in loop mode.
But, when the car makes the change (which is when the value must follow the pattern of the curve, simulating a deceleration for clutch or gear change), that same value stays at 1.
The line of code is the same:
EngineRP$$anonymous$$ = ShiftingCurve.Evaluate(Time.time);
When you say "that same value stays at 1.", what value are you referring to?
Let me see if I understand what you want to happen - You have a float variable EngineRP$$anonymous$$ that represents the speed of your car. At any point, when a clutch or gear change occurs, you want EngineRP$$anonymous$$ to decrease and then increase, causing the car to slow down and then speed up again. Is this correct?
Yes! exactly, is correct (In this case it is because the shape of the curve is in V)
Now, there is a float value, which is Engine RP$$anonymous$$, which, I assigned that when the car changes gears, that value is equal to the curve in a period of time (the change time, but that does not influence).
That is, if the curve is V-shaped, for example, the EngineRP$$anonymous$$ value goes down and up once simulating the change (this depending on the shape of the curve).
But, with that little piece of code, what happens is that when making the change, the value EngineRP$$anonymous$$ stays at the value of 1 and passed the time, returns.
if(Shifting == true)
{
EngineRP$$anonymous$$ = ShiftingCurve.Evaluate(Time.time);
}
Your answer
Follow this Question
Related Questions
Get value from a cruve like in AnimationCurve? 1 Answer
key count: 1 on curve 'curvename' error 1 Answer
Engine animation curve 1 Answer
summing up items price in runtime 1 Answer