I’m trying to make an AI, so it detects when the player is within range, to face towards him.
Below is the script that I’m using, but when the ragdoll reaches > 90 && < 270 (At the back of the transform and sides), it doesn’t rotate to those angles, only 0 - 90 && 270 - 360 (At the front and sides) . I tried to Quaternion. Inverse it, but no luck.
Does anyone have a solution?
void EnemyRotation()
{
lookingAtPlayer = enemy.GetPlayerSeen();
if (!lookingAtPlayer)
{
// Atached to the root from a different script
//public Vector3 GetDirection()
//{
// return (player.position - transform.position).normalized;
//}
var lookPos = enemy.GetDirection();
var rotation = Quaternion.LookRotation(lookPos);
APR_Parts[0].GetComponent<ConfigurableJoint>().targetRotation =
Quaternion.Slerp(APR_Parts[0].GetComponent<ConfigurableJoint>().targetRotation,
new Quaternion(rotation.x, rotation.y, rotation.z, rotation.w), Time.deltaTime * turnSpeed);
Debug.Log("Looking for the player!");
}
else
Debug.Log("Found player!");