Hi everyone!
I’d like to rotate a bone of a character following the mouseX Input. But the bone slowly goes back to its original position every frame, I’d like it to stay where it was rotated.
The character has a NavMesh moving him in like a cinematic scene where we can move the head.
Here’s the code
void Update()
{
rotX = Input.GetAxis("Mouse X") * sensitivity;
(...)
}
void LateUpdate()
{
//headRot is a float, head is the bone's transform
headRot = head.transform.rotation.y+rotX;
head.transform.localRotation = Quaternion.AngleAxis(headRot, new Vector3 (0,1,0));
}
I guess, the problem is this code line headRot = head.transform.rotation.y+rotX; You use transform.rotation, the result is a Quaternion, but you want the eulerAngles and so you have to write headRot = transform.localEulerAngles.y + rotX;
void LateUpdate()
{
//headRot is a float, head is the bone's transform
headRot = head.transform.localEulerAngles.y + rotX;;
head.transform.localRotation = Quaternion.AngleAxis(headRot, new Vector3 (0,1,0));
}
headRot is here taking the rotation as it is after the Update() function, which is the reset value of the default animation! Which is F-ing zero… So I just put that line after the last one in LateUpdate, so it takes the actual modified value. And works perfectly.