Rotate on Transform.localeulerAngels smoothly
Hi Everyone, I have attempted to search for this solution but I have had no luck.
Aim:
To rotate the head of a character model in a third person game to smoothly rotate with mouse. (Similar to GTA V looking around)
Problem:
I cannot seem to apply a rotation to localeulerAngels smoothly. Ideally I want to use Quaternion rotation to achieve this, so far no such luck. The code I paste below handles the input of the players mouse and tilts the maincamera, in this area i am also trying to achieve`enter code here` this tilt with the players head.
Please lend me a hand with your godly unity wisdom o' faithful unity lords.
Full LateUpdate
void LateUpdate()
{
//mouse Input
yaw += Input.GetAxis("Mouse X") * mouseSensitivity;
pitch -= Input.GetAxis("Mouse Y") * mouseSensitivity;
pitch = Mathf.Clamp(pitch, pitchMinMax.x, pitchMinMax.y);
//Moves the Camera
currentRotation = Vector3.SmoothDamp(currentRotation, new Vector3(pitch, yaw), ref rotationSmoothVelocity, rotationSmoothTime);
transform.eulerAngles = currentRotation;
//Restricts the the head turn amount
float headpitch = pitch;
float headyaw = transform.localEulerAngles.y;
headpitch = Mathf.Clamp(pitch, -20, 20);
if (headyaw > 45 && headyaw < 180)
{
headyaw = 45;
} else if (headyaw < 315 && headyaw > 180)
{
headyaw = 315;
}
//apply the rotation
head.transform.localEulerAngles = new Vector3(0, headyaw, headpitch);//this works
//Camera Placement
transform.position = target.position - transform.forward * dstFromTarget; Quaternion
}
first and foremost let me apologies for the formatting of the question, I had made it extremely tidy but I assure the right honourable readers that upon clicking submit the formatting is now less than perfect. $$anonymous$$y sincere apologies.