rotating with Euler Angles causes bug when bellow 0°
I want an object to rotate half the rotation of another object on X axis using this code:
targetrotation=Quaternion.LookRotation(currentGunBarrel.transform.position-hit.point);
targetrotation *= Quaternion.Euler(handRotationOffset);
//this is the line causing me problems
targetrotation = Quaternion.Euler((transform.rotation.x + targetrotation.eulerAngles.x)/2, targetrotation.eulerAngles.y, targetrotation.eulerAngles.z);
rightHandHandle.rotation=Quaternion.RotateTowards(rightHandHandle.rotation, targetrotation, smoothHandRotFactor);
My object when in rest position should be at 0° on x, and it should be able to rotate up to 90° clockwise or counter-wise.
Clockwise, from 0° to 90° it works as intended, returning a max of 45°. But counter-wise, from 0° to -90°, because it jumps to 360° as soon as it goes below 0°, it returns something around 180°. When if I input, for example -90°, i would expect it to return -45° (or 315° for that matter). I understand that's one of the perks of working with Euler Rotation, instead of using Quaternions, but since I only want to affect the X axis i cannot just slerp between the two at .5f factor. Do you guys have any Idea of how could I work around this?