# Head and body rotate threshold

I currently have a script that will rotate the player’s body when the head surpasses a maxAngle float value (I have it set at 90). It works great but I want to make it so that when the player is looking straight down or up (and/or close to it) the maxAngle value gets smaller to allow the body to rotate with the head more.

I either need to do change my angle calculation so the maxAngle shapes around the rotation sphere(?) OR I change the maxAngle to be smaller when the x rotation on the head gets bigger.

I know what I need but I don’t quite know how to achieve it. The image below is how I describe the maxAngle on the rotation sphere

Ok so here is my solution. first you need to calculate the max angle you can rotate on. This needs to be dynamic:

``````void Update () {
maxAngle = CalculateAngle ();
}

float CalculateAngle () {
Vector3 lookDir = head.forward;
Vector3 faceDir = body.forward;

float diff = Mathf.Abs(Vector3.Angle(lookDir, faceDir));
Debug.Log(diff);

// Now write the curve function
float angle = LookCurve (diff) ;

return angle;
}

float LookCurve (float diff) {
// Cats Eye (like in diagram)
return 90 * (1 - Mathf.Pow(diff / 90, 2.5f));
}
``````

The lookCurve function is basically what gives the Shape. For the linear it will simply be a diamond shape lookbox, for your more catlike one it will be the second return function. pick one or make your own. go to google and plug in this formula ‘y = 90 * (1-(x/90)^2.5)’ it will automaticall create a graph, you can then just tweek it, I suggest tweeking the power.

The next step is to Create a function that simple moves the players head towards the centre if they are out of bounds. You will need to do this yourself. Should be simple though.