Clamping a character's head rotation.

Hello, in my game the character’s heads rotate to look at the player when they are in talking range, and do so smoothly, which works great!

if (targetPosition && rc.characterInRange == true)

            Quaternion rotationAngle = Quaternion.LookRotation(targetPosition.position - trackBone.position);
            trackBone.rotation = Quaternion.Slerp(trackBone.rotation, rotationAngle, Time.deltaTime * damp);

            transform.rotation = Quaternion.Slerp(transform.rotation, originPosistion, Time.deltaTime * damp);

But the problem arises when the player goes too far behind them, at which point the neck will more or less crumple up, and so I was wondering- How can I clamp the rotation, preferably not allowing the head to rotate beyond -45 and 45 degrees? I’ve been googling this over and over but I’ve gotten stuck each time, unfortunately.

Add an if statement after finding the rotation angle. If its higher then 45 then set it to 45 degrees. If its lower then -45 set it to -45. I think this is all you’re looking for?

In the long run it may help to watch some character animation tutorials. Character Setup talks about restricting/clamping muscle space so a character never rotates past that given threshold (~15 minutes in).