quantum-space-buddies/QSB/Animation/PlayerHeadRotationSync.cs

24 lines
667 B
C#
Raw Normal View History

2020-11-22 13:57:31 +00:00
using UnityEngine;
2020-11-20 19:50:31 +00:00
namespace QSB.Animation
{
2020-12-02 21:23:01 +00:00
public class PlayerHeadRotationSync : MonoBehaviour
{
private Animator _attachedAnimator;
private Transform _lookBase;
2020-11-22 13:57:31 +00:00
2020-12-02 21:23:01 +00:00
public void Init(Transform lookBase)
{
_attachedAnimator = GetComponent<Animator>();
_lookBase = lookBase;
}
2020-11-22 13:57:31 +00:00
2020-12-03 08:28:05 +00:00
private void LateUpdate()
2020-12-02 21:23:01 +00:00
{
var bone = _attachedAnimator.GetBoneTransform(HumanBodyBones.Head);
// Get the camera's local rotation with respect to the player body
var lookLocalRotation = Quaternion.Inverse(_attachedAnimator.transform.rotation) * _lookBase.rotation;
bone.localRotation = Quaternion.Euler(0f, 0f, lookLocalRotation.eulerAngles.x);
}
}
2020-11-28 09:55:25 +00:00
}