- Home /
Problem with easing function, not getting correct result
Im trying to create an easing function, but im not getting the right result, the curve should be like the picture to the right (see image)
CODE:
public float StartValue;
public float EndValue;
public float CurrentTime;
public float DurationTime;
void Update()
{
CurrentTime += Time.deltaTime;
float y = easeInOutCubic(CurrentTime, EndValue - StartValue, Time.deltaTime, DurationTime);
float x = easeInOutCubic(CurrentTime, EndValue - StartValue, Time.deltaTime, DurationTime);
if (CurrentTime <= DurationTime)
{
transform.position += new Vector3(Time.deltaTime, y, 0);
}
else
{
Debug.Log(y);
}
}
private float easeInOutCubic(float t, float b, float c, float d)
{
t /= d/2;
if (t < 1)
return c/2*t*t*t*t + b;
t -= 2;
return -c/2 * (t*t*t*t - 2) + b;
}
easeinout.png
(47.9 kB)
easeinout.png
(47.9 kB)
Comment