- Home /
How do I interpolate a value up and then back down? Gradual interpolation
I am in need of a value starting at 0, and it gradually gets interpolated to 3, and it comes back down to 0. If i graphed this value on a coordinate plane, in relation to time, I would want the value to look like this over time: sorry me for the bad drawing, but something like this:
Answer by SamKim99 · Jun 20, 2020 at 08:16 AM
Using Animation Curve
1. Add AnimationCurve field to your MonoBehaviour class.
2. Edit curve by clicking it in inspector. (double click to add key)
Finally, you can lerp the x coordinate values to get smooth value of y.
Example code
public Image image;
public AnimationCurve curve;
// Start is called before the first frame update
void Start()
{
StartCoroutine(FillWithCurve());
}
private IEnumerator FillWithCurve()
{
float time = 0;
while (time < 1)
{
image.fillAmount = curve.Evaluate(time);
time += Time.deltaTime;
yield return null;
}
}
Result
Answer by N-8-D-e-v · Jun 18, 2020 at 08:04 PM
Check this out https://docs.unity3d.com/ScriptReference/Vector3.Lerp.html
Actually I am using quaternion.slerp at the moment, and I know how to use lerp and stuff, but my problem in my game is that quaternion doesn't have like a smoothdamp or smoothstep type function, and when I use quaternion.slerp, the interpolation is not smooth enough to my desire, and I can lower the 't' parameter, but that slows everything down, so I am not sure what to do.
$$anonymous$$aybe try slerping in lateupdate?
Your answer
Follow this Question
Related Questions
iTween ValueTo interpolation ending with wrong value 1 Answer
Dictionary doesn't exist? 1 Answer
Decreasing a value as another value increases through script 4 Answers
How to increase Value of for example "gold" every second? 3 Answers
Force uppercase in Input Field without using onValueChange? 3 Answers