more quaternion stuff

i really thought i understood rotation now but obviously not. this coroutine is called from function Update () to give a bit of movement to a static objects. The problem is that there’s a big jump after the first call (then it’s fine).

``````private var wobRange 	: float = 5.0;
private var wobbleSpeed : float = 0.9;
var killWobble 			: boolean;

function Wobble ()
{
if (docked  !locked)
{
wobbling = true;
var xRot = Random.Range(-wobRange, wobRange);
var yRot = Random.Range(-wobRange, wobRange);
var zRot = Random.Range(-wobRange, wobRange);

var startRotation = transform.rotation;
transform.Rotate(Vector3(xRot, yRot, zRot), Space.World);
var endRotation = transform.rotation;

var oldRotation = startRotation;
var newRotation = endRotation;

for (i=0; i < 2; i++)
{
t = 0.0;
while (t < 1.0)
{
t+= Time.deltaTime * wobbleSpeed;
transform.rotation = Quaternion.Lerp(oldRotation, newRotation, t);
yield;
if (killWobble) break;
}
oldRotation = endRotation;
newRotation = startRotation;
if (killWobble) break;
}
wobbling = false;
}
}
``````

also i need to get into this routine smoothly and quickly once the killWobble flag is set (it’s chaos at the moment).

f

``````unction UnDock()
{
TransRot (unDockPosition, unDockRotation);
docked = false;
}

function TransRot (targ_position : Vector3, targ_rotation : Vector3)
{
locked = true;
startPosition = transform.position;
startRotation = transform.rotation;
newRotation = Quaternion.Euler(targ_rotation);
t = 0.0;
while (t < 1.0)
{
t+= Time.deltaTime * dockingSpeed;
transform.position = Vector3.Lerp(startPosition, targ_position, t);
transform.rotation = Quaternion.Lerp(startRotation, newRotation, t);
yield;
}
locked = false;
entering = false;
}
``````

update:

i’ve got the exit from Wobble () working smoothly now it’s just the first call to it. why should var startRotation = transform.rotation; cause a problem 1st call only.
i’m a bit baffled.

Is Time.deltaTime extra large on the first frame?