I have a slide out menu in a current application. That is the ONLY object that animates. I could use the LeanTween package which I own but thinking perhaps not necessary. Could anyone share the simplest tween code with easing for a slide out menu?
Well first you need ease methods⦠hereās a bunch of them that I wrote up for my library:
Note my code staticly caches the delegates for them to conserve on gc when passing them around in my tween engineā¦
Anyways. You can then create a coroutine that passes in the start and end values over some duration⦠like so:
public IEnumerator EasePosition(Transform trans, Vector3 start, Vector3 end, float dur, Ease ease)
{
float t = 0f;
while(t < dur)
{
float sc = ease(t, 0f, 1f, dur);
trans.position = Vector3.LerpUnclamped(start, end, sc);
yield return null;
t += Time.deltaTime;
}
trans.position = end;
}
We use LerpUnclamped, because some eases like to pass the goal and come back⦠like elastic. And regular lerp will clamp the value between 0-1⦠which will lose the overshoot that the elastic effect gives.
2 Likes
Awesome. Thanks for this