I have a THIRD PERSON’S PLAYER’S head that rotates around his neck 360deg independently from his body ( I want the 360 rotate cause it is a robot) and looks up and down to follow the position of the mouse on screen.
But if I point the mouse to the players feet his head looks directly to the ground which is NOT wanted.
I only need the players head to look straight out in front of him to the horizon (which it already does that by nature) and then only look down to about 5 feet in front of him (not specifically 5 feet but you get the point)
Is there some way to CLAMP or limit the angle that the player can look up and down? I do not need the left and right clamped.
Code:
[SerializeField] Transform objectToPan; //players HEAD
void PlayerHeadLookAtMousePos()
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
Plane groupPlane = new Plane(Vector3.up, Vector3.zero);
float rayLength;
if (groupPlane.Raycast(ray, out rayLength))
{
Vector3 pointToLook = ray.GetPoint(rayLength);
objectToPan.LookAt(pointToLook);
}
}