- Home /
Rotate 90 degrees over time with Parabolic Easing.
private var rotating = false;
function RotateObject (thisTransform : Transform, degrees : Vector3, seconds : float) { if (rotating) return; rotating = true; var startRotation = thisTransform.rotation; var endRotation = thisTransform.rotation * Quaternion.Euler(degrees); var t = 0.0; //var rate = 1.0/seconds; var easeSpeed = -100; var timeHandler = 0;
while (t < 1.0) {
timeHandler += Time.deltaTime ;
var rate = easeSpeed * (timeHandler * timeHandler) + (.5) ;
//t += Time.deltaTime * rate;
t += rate;
thisTransform.rotation = Quaternion.Slerp(startRotation, endRotation, t);
//print("RATE: " + rate);
//print("TH: " + timeHandler);
//print("T: " + Time.deltaTime);
yield;
}
rotating = false;
}
Ive got this all messed up i think it is close but The
timeHandler += Time.deltaTime ;
will always return zero on the print
The idea would be for the 90 rotation to start slow, ramp up through the middle, then slow back down before resting at its +90 increment resting place.
Answer by Eric5h5 · Apr 08, 2010 at 04:59 PM
How about
private var rotating = false;
function RotateObject (thisTransform : Transform, degrees : Vector3, seconds : float) { if (rotating) return; rotating = true;
var startRotation = thisTransform.rotation;
var endRotation = thisTransform.rotation * Quaternion.Euler(degrees);
var t = 0.0;
var rate = 1.0/seconds;
while (t < 1.0) {
t += Time.deltaTime * rate;
thisTransform.rotation = Quaternion.Slerp(startRotation, endRotation, Mathf.SmoothStep(0.0, 1.0, t));
yield;
}
rotating = false;
}
Forgot to say, the reason your timeHandler
never goes above 0 is because you defined it as an int, so adding Time.deltaTime
will do nothing (unless you were getting <= 1 fps).
Could someone possibly translate this ^^ script into C# ?
Your answer
Follow this Question
Related Questions
Rotate 90 over time on mouseDown 2 Answers
Rotate object in a set amount of time 1 Answer
Transform.Rotate() stuck at 90 and 270 degrees 3 Answers
Gradually Rotate Character 90 Degrees 2 Answers