x


Quaternion.Slerp over time

im running the following inside a Coroutine

//startRotation and endRotation are cached rotations from two different Transforms
var t = 0;
while(t < rotationDuration) {
    yield return null;
    t += Time.deltaTime;
    mRoot.rotation = Quaternion.Slerp(startRotation, endRotation, Time.time * 5f);
}

mRoot.rotation = mPath.rotationEnd.rotation;

which works fine for the rotation itself. Now I tried to do the rotation "over time" using this

//this is calculated before the while() loop
var angle = Quaternion.Angle(startRotation, endRotation) ;
var rate = angle / rotationDuration;

and plugging this into the Slerp function in this way.

mRoot.rotation = Quaternion.Slerp(startRotation, endRotation, Time.deltaTime * rate);

but all I get on the GO to be rotated is a jitter, no actual rotation. Any pointers in the right direction would be appreciated.

more ▼

asked Jan 25 '11 at 05:05 AM

Steffen Franz gravatar image

Steffen Franz
379 1 2 6

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

"Time.time * 5f" won't do anything after the first second of runtime, since Slerp uses the usual 0..1 range for the third parameter. For correct usage, see the Rotation function here.

more ▼

answered Jan 25 '11 at 06:11 AM

Eric5h5 gravatar image

Eric5h5
80.2k 41 132 519

thanks for the script, pointed me in the right direction. I ended up using Quaternion.Slerp(startRotation, endRotation, Mathf.Clamp01(t/rotationDuration)); but that basically is the same idea.

Jan 25 '11 at 06:57 AM Steffen Franz
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x2163
x439
x116

asked: Jan 25 '11 at 05:05 AM

Seen: 2187 times

Last Updated: Jan 25 '11 at 05:05 AM