Hello everyone, I have this problem with Quaternions, I tried to pass the rotation of some objects to the rotation of one object, but at some angles I get the Gimbal Lock problem, like when the X rotation is 90, the Y rotation rotates on the Z axis, this is the code:
switch (axis)
{
case Axis.X:
switch (typeOfEditing)
{
case EditType.Rotation:
if (oldRotAxis != transform.localEulerAngles.x)
{
newRotAxis = transform.localEulerAngles.x - oldRotAxis;
objToMove.localRotation = Quaternion.AngleAxis(newRotAxis, Vector3.right) * objToMove.localRotation;
follower.localRotation = Quaternion.Euler(newRot);
oldRotAxis = transform.localEulerAngles.x;
}
break;
}
break;
case Axis.Z:
switch (typeOfEditing)
{
case EditType.Rotation:
if (oldRotAxis != -transform.localEulerAngles.x)
{
newRotAxis = -transform.localEulerAngles.x + oldRotAxis;
objToMove.localRotation = Quaternion.AngleAxis(newRotAxis, Vector3.forward) * objToMove.localRotation;
follower.localRotation = Quaternion.Euler(newRot);
oldRotAxis = -transform.localEulerAngles.x;
}
break;
}
break;
case Axis.Y:
switch (typeOfEditing)
{
case EditType.Rotation:
if (oldRotAxis != transform.localEulerAngles.y)
{
newRotAxis = transform.localEulerAngles.y - oldRotAxis;
objToMove.localRotation = Quaternion.AngleAxis(newRotAxis, Vector3.up) * objToMove.localRotation;
follower.localRotation = Quaternion.Euler(newRot);
oldRotAxis = transform.localEulerAngles.y;
}
break;
}
break;
}
Is there a method, to apply a rotation to each axis and evading the Gimbal Lock? I have tried also the Quaternion.Euler but gives me the same results.