I’m looking to create a linear movement for an object which has its speed controlled with a circular easing script (think space ship going to warp). I have found the following code snippet for the type of movement I wish to create but don’t know how to implement it…
I have a space ship I want to apply this to and I know the starting position and the ending position.
it is from this website Easing Equations
// circular easing in/out - acceleration until halfway, then deceleration
Math.easeInOutCirc = function (t, b, c, d) {
t /= d/2;
if (t < 1) return -c/2 * (Math.sqrt(1 - tt) - 1) + b;
t -= 2;
return c/2 * (Math.sqrt(1 - tt) + 1) + b;
};
Not sure what your problem is, it tells you what everything is, it even gives you the code. If you can’t understand it perhaps using these kind of tweens is not a good idea.
This might help: http://robertpenner.com/easing/penner_chapter7_tweening.pdf
You’ll probably want to set these up in a static class, there might even be something on the Wiki that has this already, but I’d do it a bit like this:
public static Vector3 EaseInOutCirc (Vector3 start, Vector3 end, float duration, float time) {
time /= duration * 0.5f;
if (time < 1f) {
return -end * 0.5f * (Mathf.Sqrt(1f - time * time) - 1f) + start;
}
time -= 2f;
return end* 0.5f * (Mathf.Sqrt(1f - time * time) + 1f) + start;
}
1 Like