When using ik to llok at target for some reason if the target is moving and coming from behind the player head will not rotate completely to the side

using System.Collections; using UnityEngine;  [RequireComponent(typeof(Animator))] public class LookAtTarget : MonoBehaviour {     public Transform lookObj = null;     public float finalLookWeight;     public float weightDamping = 1.5f;      protected Animator animator;      void Start()     {         animator = GetComponent<Animator>();     }      //a callback for calculating IK     void OnAnimatorIK()     {         if (lookObj != null)         {             Vector3 flattenedLookAtVector = Vector3.ProjectOnPlane(lookObj.position - transform.position, transform.up);             float dotProduct = Vector3.Dot(transform.forward, flattenedLookAtVector);             float lookWeight = Mathf.Clamp(dotProduct, 0f, 1f);             finalLookWeight = Mathf.Lerp(finalLookWeight, lookWeight, Time.deltaTime * weightDamping);             float bodyWeight = finalLookWeight * .5f;              animator.SetLookAtWeight(finalLookWeight, bodyWeight);             animator.SetLookAtPosition(lookObj.position);         }     } } 

When an object that is rotating around my player the head will rotate looking at the target to the side if the target that is rotating around coming from the front of the player but if the target is coming from behind the player will not rotate the head completely like when the target is coming from the front.

I tried to switch the line :

float lookWeight = Mathf.Clamp(dotProduct, 0f, 1f); 


float lookWeight = Mathf.Abs(dotProduct); 

When using Abs instead Clamp it fix the problem but than the looking at smoothing is less smooth when using Clamp. It is smooth but not as with Clamp.

This screenshot is when the basketball the object the player is looking at coming from the front to the back the player is looking at it even when it’s on the side which is good and what I wan it to behave like.

Basketball is rotating around the player in this frame is when the basketball came from the front

In this screenshot the basketball is keep rotating around the player and coming moving forward from behind from the other side and for some reason when it come from behind the player start looking at not when the basketball is on the side but a bit more when the basketball is a bit more in front of the player :

Basketball is coming from behind but the player detect the basketball only when the basketball get much more to the front of the player.