#Gimble Lock Issue (I think)

1 messages · Page 1 of 1 (latest)

inner siren
#
    private void RotateObject(GameObject obj)
    {
        //set the starting rotation.
        obj.transform.rotation = Quaternion.Euler(prefabRotation);

        //assign each rotation value by numOfFrames.
        int direction = invertRotation ? -1 : 1;
        float speed = 360f / numOfFrames * direction;
        Vector3 speedPerFrame = Vector3.zero;
        if (xRotation) speedPerFrame.x = speed;
        if (yRotation) speedPerFrame.y = speed;
        if (zRotation) speedPerFrame.z = speed;


        //for each frame, Rotate object and snap a picture of it, and save it in the specified location.
        for (int i = 0; i < numOfFrames; i++)
        {
            DirectoryInfo info = BuildDirectory(Application.dataPath, GIF_FramePath, obj.name + "_Frames");
            FileInfo fileInfo = new FileInfo(Path.Combine(info.FullName, $"{i:000}.png"));

            obj.transform.Rotate(speedPerFrame);
            TakeSnapShot(fileInfo, obj, true);
        }
    }```
#

Singular rotation Axis: Loops fine
Multiple rotation Axis: Gimble lock (I think)

#

Anyone see why it would do this?

vale quest
#

Could try doing a Rotate for each axis, instead of applying all axes in one rotation call

#

Not sure

jolly crystal
#

Have you tried using Space.World in Transform.Rotate?

inner siren
fossil stump
#

what exactly is happening that shouldn't be?

inner siren
#

the second gif, it doesnt loop. it skips if rotating on more than 1 axi

vale quest
#

Honestly it looks like it loops, but its like 1.5 rotations instead of 1

jolly crystal
#

Oh. If that kind of precision is required, don't use Rotate. There's no reason you need to be adding relative rotation at each frame, then you need to very carefully calculate the right delta. You can just calculate what angle it should be at for each frame and create a completely rotation for that.

vale quest
inner siren
#

this isnt a runtime operation, it's in the editor so the forloop is required to set the rotation per numOfFrames and grab a picture of it

vale quest
#

Oops I changed numOfFrames to i

atomic nebula
#

ususaly if i need the axis spinng independ i make one gamobject per axis

jolly crystal
# inner siren How would I do that?

Calculate a normalized t value for each frame and use that to lerp from the start rotation to the end rotation, in this case from angle 0 to 360.

Something like this:

Vector3 eulerAngles = Vector3.zero;
if (xRotation) eulerAngles.x = 1;
if (yRotation) eulerAngles.y = 1;
if (zRotation) eulerAngles.z = 1;

if (invertRotation) eulerAngles = -eulerAngles;

Quaternion startRotation = Quaternion.Euler(prefabRotation);

for (int i = 0; i < numOfFrames; i++)
{
    float t = (float) i / numOfFrames;
    float angle = 360 * t;
    Quaternion rotation = Quaternion.Euler(eulerAngles * angle);
    obj.transform.rotation = startRotation * rotation;
    ...
}
inner siren
#

would that rotate from the starting rotation? obj.transform.rotation = Quaternion.Euler(prefabRotation);

#

so it'd add onto this ^

jolly crystal
#

Fixed

inner siren
#

are you casting i to float for the division calc (so it wont return 0) ?

#

rotating on all 3 Axi! holy shit

#

it has a weird arc, but perhaps thats normal haha

jolly crystal
inner siren
#

Thank you very much!