When aiming, I dont want my full character to rotate around the X axis, but only the upper-body.
Now I’ve got the upper-body transform, but I cant seem to rotate it.
Could anyone help me figure this out?
void Start()
{
var hips = transform.Find("mixamorig:Hips");
upperBody = hips.Find("mixamorig:Spine");
}
This gets the spine transform through the hips child of the character (I couldn’t access it directly, only through hips.)
if (isAiming)
{
var xMouse = Input.GetAxis("Mouse X") * turnSpeed * mouseTurnMultiplier;
upperBody.Rotate(0, xMouse, 0);
var yMouse = -Input.GetAxis("Mouse Y") * turnSpeed * mouseTurnMultiplier;
upperBody.Rotate(yMouse, 0, 0);
}
This does not rotate the upper-body of the character, and I’m stumped as to how.
I have no constraints on the parent either.
Would greatly appreciate help with this!
As you can see in Unity’s script lifecycle, animations are processed after scripts’ Update() functions are called:
This means that all changes you make in Update() are overriden by the animator, so you have to do the changes after ProcessAnimation().
You can use LateUpdate() to change Transforms or use OnAnimatorIK(), but this function is only called if the script is in the same GameObject in hierarchy as the Animator.