- Home /
Rotation relations and EulerAngles's mess
I'm building an Inverse Kinematics rig, I am automating the movement of the clavicle and the scapula right now. What I want to do is use the Y rotation of the shoulder to rotate the y axis of the clavicle to a maximum of +40~50 and -20 (it shouldn't change the local rotation if a parent rotates) but now I have stuttering problems once it crosses the 180 cap because the code reverse the rotation at that moment, the result rotation isnt precise too, probably because of the mess I made with calculations of those angles.
I still did not find how to turn the Z axis correctly when the body rotates, and still have to code a position and rotaion transform for the scapula by using half or less of the clavicle rotation, wich by using this method will be even more buggy.
Would it be possible to use quaternions for this? If so, how ?
void CalculateR_Scapula(){
//Y axis rotation
float RotY = R_Shoulder.eulerAngles.y;
//Avatar = the highest parent in the hierarchy wich moves and rotate the whole body
float BodyRotationY = Avatar.transform.eulerAngles.y;
if(BodyRotationY > 180){
BodyRotationY = BodyRotationY - 360;
}
if(RotY > 180){
RotY = Mathf.Clamp(RotY, 310 + BodyRotationY, 360 + BodyRotationY);
}
else {RotY = Mathf.Clamp(RotY, 0 + BodyRotationY, 20 + BodyRotationY);}
//Z axis Rotation
float RotZ = R_Shoulder.eulerAngles.z;
//t-pose y axis = 180, so clamp from -5 to + 40
RotZ = Mathf.Clamp (RotZ, BaseRotR_Clavicle.z-5, BaseRotR_Clavicle.z+40);
//BaseRot = the rotation of each transform at void Start()
Quaternion NewRot = Quaternion.Euler (BaseRotR_Clavicle.x, BaseRotR_Clavicle.y + RotY, BaseRotR_Clavicle.z + RotZ + 180);
//Used to smooth out the stuttering when Y rotation = 180, doesn't really work that well at all
R_Clavicle.transform.rotation = Quaternion.Lerp (R_Clavicle.transform.rotation, NewRot, Time.deltaTime * 20);
}
Thank you for taking the time to read.
Your answer
Follow this Question
Related Questions
How to convert quaternion to vector3 with specific multiplication order? 5 Answers
Rotating an object around the centre of its mesh, using Quarternion AxisAngle 1 Answer
How to Aim Animator.SetIKRotation() to direction WRT hand bone rotation offset 0 Answers
Duplicating rotation with axis constraints 1 Answer
Get player orientation, but only one Euler angle is non-zero 2 Answers