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);
}
}```
#Gimble Lock Issue (I think)
1 messages · Page 1 of 1 (latest)
Singular rotation Axis: Loops fine
Multiple rotation Axis: Gimble lock (I think)
Anyone see why it would do this?
Could try doing a Rotate for each axis, instead of applying all axes in one rotation call
Not sure
Have you tried using Space.World in Transform.Rotate?
Yep! same thing happens
what exactly is happening that shouldn't be?
the second gif, it doesnt loop. it skips if rotating on more than 1 axi
Honestly it looks like it loops, but its like 1.5 rotations instead of 1
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.
How would I do that?
Something like this?
obj.transform.eulerAngles = speedPerFrame * i;```
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
Oops I changed numOfFrames to i
ususaly if i need the axis spinng independ i make one gamobject per axis
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;
...
}
would that rotate from the starting rotation? obj.transform.rotation = Quaternion.Euler(prefabRotation);
so it'd add onto this ^
Fixed
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
Yeah, otherwise it will do integer division.
Thank you very much!