unit – Gently turn the parents when the child's bone overcomes the rotation

I am building a player controller.

While aiming, the player can rotate the chest bone. This seems as if the character points in different directions.

Only the breast bone should be allowed to rotate within a certain range.
If this range is exceeded (to the left or to the right), the chest bone must remain in its current rotation, and the player must turn in its place.

I created a code. The thoracic bone rotates smoothly, but the object of the player's game rotates in a stuttering way.

How could "transfer" the smooth rotation of the chest bone to the object of the player's game if the range is exceeded?

private void pHandle_LateUpdate_Aim ()
Quaternion oldNeckRotation = Neck.transform.rotation;

// The old entry disappears before capturing new, so we do not hide the most recent data.
float yawBlend = Mathf.Pow (1.0f - Aim_yawInputFalloff, referenceFramerate * Time.deltaTime);
// A Lerp to zero is the same as a multiplication by the mixing factor.
Chest_yawRate * = yawBlend;
// Accelerate with the movement of the mouse over the previous frame.
// (You may need adjustments for the resolution of the screen).
Chest_yawRate + = Input.GetAxis ("Mouse X");

float yawDelta = Chest_yawSpeed ​​* Chest_yawRate * Time.deltaTime;
float offCenterYaw = Chest_currentYaw - Chest_yawCenter;

float fDesiredChestYaw = Chest_currentYaw + yawDelta;
float fHeroRotation = 0f;

if (fDesiredChestYaw> Chest_rotateRange)
fHeroRotation = (fDesiredChestYaw - Chest_rotateRange);
// we do not rotate the chest beyond the "Chest_rotateRange" allowed, so we just act as if the user did not move the mouse
// however, this results in a stuttering movement for some reason
Chest_yawRate = 0;
yawDelta = Chest_yawSpeed ​​* Chest_yawRate * Time.deltaTime;
else if (fDesiredChestYaw < -Chest_rotateRange)
        fHeroRotation = (Chest_rotateRange + fDesiredChestYaw);
        Chest_yawRate = 0;
        yawDelta = Chest_yawSpeed * Chest_yawRate * Time.deltaTime;
        // If we're moving away from the center, slow down as we approach the edge.
        if (yawDelta * offCenterYaw > 0)
float extremityYaw = offCenterYaw / Aim_yawMaxRange;
yawDelta * = 1.0f - extremityYaw * extremityYaw;
this.transform.Rotate (0, fHeroRotation, 0);

// Make sure we never exceed the allowed range.
Chest_currentYaw = Mathf.Clamp (Chest_currentYaw + yawDelta,
Chest_yawCenter - Aim_yawMaxRange,
Chest_yawCenter + Aim_yawMaxRange);

Vector3 nNewChestRotation = new Vector3 (Chest.localEulerAngles.x, Chest_currentYaw, Chest.localEulerAngles.z);
Chest.localRotation = Quaternion.Euler (nNewChestRotation);

Quaternion newNeckRotation = Neck.transform.rotation;

// The neck should not rotate with the chest. So first I counteracted it against the new rotation of the chest, then I turned it a little towards the rotation of the chest
Neck.transform.rotation = Quaternion.Lerp (oldNeckRotation, newNeckRotation, neckFollowChest);