diff --git a/QSB/Animation/AnimationSync.cs b/QSB/Animation/AnimationSync.cs index 0b935b79..43bffa09 100644 --- a/QSB/Animation/AnimationSync.cs +++ b/QSB/Animation/AnimationSync.cs @@ -29,6 +29,10 @@ namespace QSB.Animation public AnimatorMirror Mirror { get; private set; } public AnimationType CurrentType = AnimationType.PlayerUnsuited; + public Animator Animator + { + get { return _bodyAnim; } + } private void Awake() { @@ -129,6 +133,9 @@ namespace QSB.Animation body.Find("Traveller_Mesh_v01:Traveller_Geo/Traveller_Mesh_v01:PlayerSuit_Helmet").gameObject.layer = 0; InitCrouchSync(); + + var ikSync = body.gameObject.AddComponent(); + QSB.Helper.Events.Unity.RunWhen(() => Player.Camera != null, () => ikSync.Init(Player.Camera.transform)); } private void InitCrouchSync() diff --git a/QSB/Animation/Events/ChangeAnimTypeEvent.cs b/QSB/Animation/Events/ChangeAnimTypeEvent.cs index f204ee8c..415c90fc 100644 --- a/QSB/Animation/Events/ChangeAnimTypeEvent.cs +++ b/QSB/Animation/Events/ChangeAnimTypeEvent.cs @@ -23,7 +23,7 @@ namespace QSB.Animation.Events public override void OnReceiveRemote(EnumMessage message) { - QSBPlayerManager.GetPlayer(message.AboutId).Animator.SetAnimationType(message.Value); + QSBPlayerManager.GetPlayer(message.AboutId).AnimationSync.SetAnimationType(message.Value); QSBPlayerManager.GetSyncObject(message.AboutId).CheckInstrumentProps(message.Value); } } diff --git a/QSB/Animation/Events/PlayerSuitEvent.cs b/QSB/Animation/Events/PlayerSuitEvent.cs index 81626920..b2924ab4 100644 --- a/QSB/Animation/Events/PlayerSuitEvent.cs +++ b/QSB/Animation/Events/PlayerSuitEvent.cs @@ -34,7 +34,12 @@ namespace QSB.Animation var player = QSBPlayerManager.GetPlayer(message.AboutId); player?.UpdateState(State.Suit, message.ToggleValue); - var animator = player.Animator; + if (!player.IsReady) + { + return; + } + + var animator = player.AnimationSync; var type = message.ToggleValue ? AnimationType.PlayerSuited : AnimationType.PlayerUnsuited; animator.SetAnimationType(type); } @@ -42,7 +47,7 @@ namespace QSB.Animation public override void OnReceiveLocal(ToggleMessage message) { QSBPlayerManager.LocalPlayer.UpdateState(State.Suit, message.ToggleValue); - var animator = QSBPlayerManager.LocalPlayer.Animator; + var animator = QSBPlayerManager.LocalPlayer.AnimationSync; var type = message.ToggleValue ? AnimationType.PlayerSuited : AnimationType.PlayerUnsuited; animator.CurrentType = type; } diff --git a/QSB/Animation/PlayerHeadRotationSync.cs b/QSB/Animation/PlayerHeadRotationSync.cs index bf68b3d6..6cf90e70 100644 --- a/QSB/Animation/PlayerHeadRotationSync.cs +++ b/QSB/Animation/PlayerHeadRotationSync.cs @@ -1,11 +1,24 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; +using UnityEngine; namespace QSB.Animation { - class PlayerHeadRotationSync + public class PlayerHeadRotationSync : MonoBehaviour { + private Animator _attachedAnimator; + private Transform _lookBase; + + public void Init(Transform lookBase) + { + _attachedAnimator = GetComponent(); + _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); + } } } diff --git a/QSB/Instruments/InstrumentsManager.cs b/QSB/Instruments/InstrumentsManager.cs index 3953ea16..cba35394 100644 --- a/QSB/Instruments/InstrumentsManager.cs +++ b/QSB/Instruments/InstrumentsManager.cs @@ -56,7 +56,6 @@ namespace QSB.Instruments private void SetupInstruments() { - DebugLog.DebugWrite($"Setup instruments {PlayerId}"); var bundle = QSB.InstrumentAssetBundle; ChertDrum = MakeChertDrum(bundle); } @@ -69,10 +68,6 @@ namespace QSB.Instruments mf.sharedMesh = bundle.LoadAsset("assets/Chert/hourglasstwinsmeshescharacters2.asset") as Mesh; var mr = drum.AddComponent(); mr.sharedMaterial = GameObject.Find("NewDrum:polySurface2").GetComponent().material; - foreach (var item in mr.sharedMaterial.shaderKeywords) - { - DebugLog.DebugWrite(item); - } drum.transform.parent = rootObj; drum.transform.rotation = rootObj.rotation; drum.transform.localPosition = Vector3.zero; @@ -93,7 +88,7 @@ namespace QSB.Instruments { return; } - _savedType = Player.Animator.CurrentType; + _savedType = Player.AnimationSync.CurrentType; CameraManager.Instance.SwitchTo3rdPerson(); SwitchToType(type); } @@ -112,7 +107,7 @@ namespace QSB.Instruments { DebugLog.DebugWrite($"switch to type {type} player {PlayerId}"); GlobalMessenger.FireEvent(EventNames.QSBChangeAnimType, QSBPlayerManager.LocalPlayerId, type); - QSBPlayerManager.LocalPlayer.Animator.SetAnimationType(type); + QSBPlayerManager.LocalPlayer.AnimationSync.SetAnimationType(type); CheckInstrumentProps(type); } diff --git a/QSB/Player/PlayerInfo.cs b/QSB/Player/PlayerInfo.cs index 366c91c3..27ec6bc4 100644 --- a/QSB/Player/PlayerInfo.cs +++ b/QSB/Player/PlayerInfo.cs @@ -31,9 +31,9 @@ namespace QSB.Player public GameObject CurrentDialogueBox { get; set; } // Animation - public AnimationSync Animator => QSBPlayerManager.GetSyncObject(PlayerId); - public bool PlayingInstrument => Animator.CurrentType != AnimationType.PlayerSuited - && Animator.CurrentType != AnimationType.PlayerUnsuited; + public AnimationSync AnimationSync => QSBPlayerManager.GetSyncObject(PlayerId); + public bool PlayingInstrument => AnimationSync.CurrentType != AnimationType.PlayerSuited + && AnimationSync.CurrentType != AnimationType.PlayerUnsuited; public PlayerInfo(uint id) { diff --git a/QSB/QSB.csproj b/QSB/QSB.csproj index 7b3a7cea..ab755ea4 100644 --- a/QSB/QSB.csproj +++ b/QSB/QSB.csproj @@ -130,6 +130,7 @@ +