set a Quaternion x times slower than a other Quaternion.

Hey All,

I have a 2D object which is manipulated by physics, it is restricted to only rotate around the z axis.
There’s a second object which should rotate together with the first one but 12 times slower.

It’s seems simple but I’m having difficulties with this because the object rotation goes from 179 to -179 when rotation around 180 degrees which is no problem on the first object but is on the second when dividing by 12… .

// first object
float sourceAngle;
Vector3 directionVector;
firstObject.transform.rotation.ToAngleAxis (out sourceAngle, out directionVector);

// second object
Quaternion quat = Quaternion.AngleAxis (sourceAngle / 12.0f, directionVector);
secondObject.transform.rotation = quat;

Would really appreciate if somebody can point me in the right direction?

You are just changing the angle moved but not using time. The first must be moving at an angle per second or something, so you have to set the second to 1/12 that. Don’t ask me how because I haven’t used quaternions that much.

Thx for your answer.
Are you referring to having things in motion?
Like I said at the beginning of my post the first object is already moving due some physics code which I didn’t include in the example.

I’m actually stuck at getting a more linear rotation out of the quaternion to apply it to a different object with some multiplication or division.

targetAngle = targetAngle + Mathf.Ceil(-targetAngle / 360f) * 360f;

That code should wrap the the angle between 0-360 rather than -180 to 180. I’m not really sure that’s going to solve your issue though, all dividing the angle by 12 will do is change the range of its rotation from 0-360 to 0-30. Are you sure you don’t want to take into account the difference of change and divide THAT by 12 so it “lags behind” the rotation of the other object?

Something like:

float lastAngle = 0f;

float WrapAngle(float angle)
{
   return angle + Mathf.Ceil(-angle / 360.0f) * 360.0f;
}

void Update()
{
    float currentAngle = WrapAngle(target.rotation.eulerAngles.z);
    float delta = (currentAngle - lastAngle) / 12.0f;

   transform.Rotate(0f, 0f, delta);

   lastAngle = currentAngle;
}

Hey,

Indeed a lot of the things I tried do divide by 12 but keep it between a fixed range because the Quaternion of the first object never gets bigger than 180.

I solved my problem by tracking one of the childnodes on my firstobject.
Calculating it’s rotation from the position with a atan2.
Then keeping track of the rotation with Mathf.deltaAngle.

The monthTextHolder is my object2.

    // track this item to get linear rotation.
        var trackerObject = daysText [0].transform;
        var p = trackerObject.position;
        p -= trackerObject.parent.transform.position;
        var trackerAngle = Mathf.Atan2 (p.y, p.x) * Mathf.Rad2Deg;

        float div = Mathf.DeltaAngle (previousTrackerAngle, trackerAngle);

        angle += div;
        monthTextHolder.transform.localRotation = Quaternion.Euler (0,0,