Forward angles

Hello guys, I need your help. So I have a problem with checking the angles from the forward of the character. Player rotates his torso and after certain angle it should update it’s forward(update feet) and check for angles again. Hope you will understand.Maybe the picture will explain it better.
175341-capture.png

You can do something like this. Keep in mind that this is not tested, but it should provide you a starting point.

void TurnToMouse(Transform head, Transform feet, Vector3 mouseWorldPosition, float angleLimit, bool flatten)
        {
            Vector3 headForward = head.forward;
            Vector3 directionToMouse = mouseWorldPosition - head.position;

            //flattens to x,z plane this is assuming you do not want the feet to turn. 
            if (flatten)
            {
                directionToMouse.y = 0;
                headForward.y = 0;
            }

            if(Vector3.Angle(headForward, directionToMouse)>angleLimit)
            {
                feet.rotation = Quaternion.LookRotation(directionToMouse);
            }
        }

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
//mouseTestPos = Mathf.Clamp((Input.mousePosition.x / Screen.width) * 2 - 1, -1.0f, 1.0f);
// animator.SetFloat(“Mouse”, mouseTestPos);
public class PlayerLookAtDemo : MonoBehaviour
{
public Vector3 mousePos;
public Vector3 mouseWorldPoint;
public Vector3 direction;
public Vector3 directionOnPlane;
public Quaternion rotationOnPlane;
public float angleBetween = 0f;
public float angularThreshold = 35f;
private const float DebugLineScaler = 10f;
public void Update()
{
var mouse = Mouse.current;
mousePos = new Vector3(mouse.position.x.ReadValue(), mouse.position.y.ReadValue(),
Camera.main.transform.position.y - transform.position.y);
mouseWorldPoint = Camera.main.ScreenToWorldPoint(mousePos);
direction = (mouseWorldPoint - transform.position).normalized;
directionOnPlane = Vector3
.ProjectOnPlane(Camera.main.transform.rotation * Vector3.forward,
transform.up).normalized;
if (directionOnPlane.sqrMagnitude == 0f)
{
directionOnPlane = Vector3
.ProjectOnPlane(Camera.main.transform.rotation * Vector3.up, transform.up)
.normalized;
}
rotationOnPlane = Quaternion.LookRotation(directionOnPlane, transform.up);
var resultingVector = rotationOnPlane * direction;
angleBetween = Vector3.Angle(transform.forward, resultingVector);
Debug.DrawRay(transform.position, transform.forward * DebugLineScaler, Color.blue);
Debug.DrawRay(transform.position, resultingVector * DebugLineScaler, Color.red);
if (angleBetween > angularThreshold)
{
var newRotation = Quaternion.LookRotation(resultingVector, transform.up).eulerAngles;
transform.rotation = Quaternion.Euler(0, newRotation.y, 0);
}
else
{
float mouseTestPos = Mathf.Clamp((Input.mousePosition.x / Screen.width) * 2 - 1, -1.0f, 1.0f);
gameObject.GetComponent().SetFloat(“Mouse”, mouseTestPos);
}
}
}