I am stuck with rotating a GameObject on the Z axis with easing.
I want to achieve an effect like in this game:
Here, the ring of targets starts rotating periodically. It starts slower, than rotation speed increases and again towards the end it decreases.
My speed of rotation is constant and I tried few approaches but with no luck. In my current code, I lerp new angle and then I substract previous angle from it to get actual angle needed for a turn.
private float degreesToTurn = 45;
private float t = 0;
private float previosDegrees = 0;
private float actualDegrees = 0;
void Update() {
float degrees = GetDegreesToTurn();
transform.Rotate(Vector3.forward * degrees);
}
private float GetDegreesToTurn() {
t += 0.05f * Time.deltaTime * 10;
actualDegrees = Mathf.Lerp(0, degreesToTurn, t);
float rotateDegree = actualDegrees - previosDegrees;
previosDegrees = actualDegrees;
return rotateDegree;
}
I tried to increase t
variable till I reached degreesToTurn / 2 but and then decrease it but that resulted not in easing but in rotating back.
Also I tried to use Quaternions but the problem is that I want to be able to rotate targets over 360 degrees which must result in N amount of spins. Quaternions don't allow me to do that.