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

24 lines
770 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-11-22 13:57:31 +00:00
public class PlayerHeadRotationSync : MonoBehaviour
2020-11-20 19:50:31 +00:00
{
2020-11-22 13:57:31 +00:00
private Animator _attachedAnimator;
private Transform _lookBase;
public void Init(Transform lookBase)
{
_attachedAnimator = GetComponent<Animator>();
_lookBase = lookBase;
}
void LateUpdate()
{
var bone = _attachedAnimator.GetBoneTransform(HumanBodyBones.Head);
2020-11-22 14:25:10 +00:00
// Get the camera's local rotation with respect to the player body
var lookLocalRotation = Quaternion.Inverse(_attachedAnimator.transform.rotation) * _lookBase.rotation;
2020-11-22 13:57:31 +00:00
bone.localRotation = Quaternion.Euler(0f, 0f, lookLocalRotation.eulerAngles.x);
}
2020-11-20 19:50:31 +00:00
}
2020-11-28 09:55:25 +00:00
}