quantum-space-buddies/QSB/Animation/PlayerHeadRotationSync.cs
2020-11-22 13:57:31 +00:00

25 lines
751 B
C#

using UnityEngine;
namespace QSB.Animation
{
public class PlayerHeadRotationSync : MonoBehaviour
{
private Animator _attachedAnimator;
private Transform _lookBase;
public void Init(Transform lookBase)
{
_attachedAnimator = GetComponent<Animator>();
_lookBase = lookBase;
}
void LateUpdate()
{
var bone = _attachedAnimator.GetBoneTransform(HumanBodyBones.Head);
// Get the camera's local rotation with respect to the head
var lookLocalRotation = Quaternion.Inverse(bone.transform.rotation) * _lookBase.rotation;
bone.localRotation = Quaternion.Euler(0f, 0f, lookLocalRotation.eulerAngles.x);
}
}
}