diff --git a/ml_prm/RagdollController.cs b/ml_prm/RagdollController.cs index 9e3b001..602e56e 100644 --- a/ml_prm/RagdollController.cs +++ b/ml_prm/RagdollController.cs @@ -1,7 +1,7 @@ using ABI.CCK.Components; using ABI_RC.Core.InteractionSystem; using ABI_RC.Core.Player; -using ABI_RC.Core.Player.AvatarTracking.Local; +using ABI_RC.Core.Savior; using ABI_RC.Systems.IK.SubSystems; using ABI_RC.Systems.MovementSystem; using RootMotion.Dynamics; @@ -18,7 +18,6 @@ namespace ml_prm VRIK m_vrIK = null; float m_vrIkWeight = 1f; - LocalHeadPoint m_headPoint = null; bool m_inVr = false; bool m_enabled = false; @@ -33,6 +32,7 @@ namespace ml_prm bool m_avatarReady = false; Vector3 m_lastPosition = Vector3.zero; Vector3 m_velocity = Vector3.zero; + Vector3 m_ragdollLastPos = Vector3.zero; RagdollToggle m_avatarRagdollToggle = null; RagdollTrigger m_customTrigger = null; @@ -68,7 +68,6 @@ namespace ml_prm void Start() { m_inVr = Utils.IsInVR(); - m_headPoint = this.GetComponent(); m_puppetRoot = new GameObject("[PlayerAvatarPuppet]").transform; m_puppetRoot.parent = PlayerSetup.Instance.transform; @@ -103,9 +102,20 @@ namespace ml_prm void Update() { - Vector3 l_pos = PlayerSetup.Instance.transform.position; - m_velocity = (m_velocity + (l_pos - m_lastPosition) / Time.deltaTime) * 0.5f; - m_lastPosition = l_pos; + if(m_enabled && m_avatarReady) + { + Vector3 l_dif = m_puppetReferences.hips.position - m_ragdollLastPos; + PlayerSetup.Instance.transform.position += l_dif; + m_puppetReferences.hips.position -= l_dif; + m_ragdollLastPos = m_puppetReferences.hips.position; + } + + if(!m_enabled && m_avatarReady) + { + Vector3 l_pos = PlayerSetup.Instance.transform.position; + m_velocity = (m_velocity + (l_pos - m_lastPosition) / Time.deltaTime) * 0.5f; + m_lastPosition = l_pos; + } if(m_avatarReady && !m_reachedGround && MovementSystem.Instance.IsGrounded()) m_reachedGround = true; @@ -142,12 +152,6 @@ namespace ml_prm foreach(var l_link in m_boneLinks) l_link.Item1.CopyGlobal(l_link.Item2); - - if(m_inVr && Settings.VrFollow) - { - Transform l_camera = PlayerSetup.Instance.GetActiveCamera().transform; - l_camera.position = m_headPoint.GetPointPosition(); - } } } @@ -382,7 +386,16 @@ namespace ml_prm { Vector3 l_pos = PlayerSetup.Instance.transform.position; Quaternion l_rot = PlayerSetup.Instance.transform.rotation; - MovementSystem.Instance.lastSeat.ExitSeat(); + + if(MetaPort.Instance.isUsingVr) + { + MetaPort.Instance.isUsingVr = false; + MovementSystem.Instance.lastSeat.ExitSeat(); + MetaPort.Instance.isUsingVr = true; + } + else + MovementSystem.Instance.lastSeat.ExitSeat(); + PlayerSetup.Instance.transform.position = l_pos; PlayerSetup.Instance.transform.rotation = Quaternion.Euler(0f, l_rot.eulerAngles.y, 0f); } @@ -419,6 +432,7 @@ namespace ml_prm foreach(Collider l_collider in m_colliders) l_collider.enabled = true; + m_ragdollLastPos = m_puppetReferences.hips.position; m_downTime = 0f; m_enabled = true; @@ -436,22 +450,8 @@ namespace ml_prm foreach(Rigidbody l_body in m_rigidBodies) l_body.isKinematic = true; - if(m_puppetReferences.hips != null) - { - Vector3 l_hipsPos = m_puppetReferences.hips.position; - - if(!Settings.RestorePosition) - { - if(m_inVr) - { - Vector3 l_diff = l_hipsPos - PlayerSetup.Instance._avatar.transform.position; - Vector3 l_playerPos = PlayerSetup.Instance.transform.position; - PlayerSetup.Instance.transform.position = l_playerPos + l_diff; - } - else - PlayerSetup.Instance.transform.position = l_hipsPos; - } - } + PlayerSetup.Instance.transform.position = m_puppetReferences.hips.position; + PlayerSetup.Instance.transform.position -= (PlayerSetup.Instance.transform.rotation * PlayerSetup.Instance._avatar.transform.localPosition); foreach(Collider l_collider in m_colliders) l_collider.enabled = false; diff --git a/ml_prm/Settings.cs b/ml_prm/Settings.cs index 90bc936..86f05e6 100644 --- a/ml_prm/Settings.cs +++ b/ml_prm/Settings.cs @@ -11,7 +11,6 @@ namespace ml_prm { Hotkey = 0, VelocityMultiplier, - RestorePosition, MovementDrag, AngularDrag, Gravity, @@ -22,14 +21,12 @@ namespace ml_prm RecoverDelay, Slipperiness, Bounciness, - ViewVelocity, - VrFollow, + ViewVelocity } enum UiElementIndex { Hotkey = 0, - RestorePosition, Gravity, PointersReaction, IgnoreLocal, @@ -38,7 +35,6 @@ namespace ml_prm Slipperiness, Bounciness, ViewVelocity, - VrFollow, VelocityMultiplier, MovementDrag, AngularDrag, @@ -49,7 +45,6 @@ namespace ml_prm public static bool Hotkey { get; private set; } = true; public static float VelocityMultiplier { get; private set; } = 2f; - public static bool RestorePosition { get; private set; } = false; public static float MovementDrag { get; private set; } = 2f; public static float AngularDrag { get; private set; } = 2f; public static bool Gravity { get; private set; } = true; @@ -61,11 +56,9 @@ namespace ml_prm public static bool Slipperiness { get; private set; } = false; public static bool Bounciness { get; private set; } = false; public static bool ViewVelocity { get; private set; } = false; - public static bool VrFollow { get; private set; } = true; static public event Action SwitchChange; static public event Action HotkeyChange; - static public event Action RestorePositionChange; static public event Action VelocityMultiplierChange; static public event Action MovementDragChange; static public event Action AngularDragChange; @@ -78,7 +71,6 @@ namespace ml_prm static public event Action SlipperinessChange; static public event Action BouncinessChange; static public event Action ViewVelocityChange; - static public event Action VrFollowChange; static MelonLoader.MelonPreferences_Category ms_category = null; static List ms_entries = null; @@ -92,7 +84,6 @@ namespace ml_prm { ms_category.CreateEntry(ModSetting.Hotkey.ToString(), Hotkey), ms_category.CreateEntry(ModSetting.VelocityMultiplier.ToString(), VelocityMultiplier), - ms_category.CreateEntry(ModSetting.RestorePosition.ToString(), RestorePosition), ms_category.CreateEntry(ModSetting.MovementDrag.ToString(), MovementDrag), ms_category.CreateEntry(ModSetting.AngularDrag.ToString(), AngularDrag), ms_category.CreateEntry(ModSetting.Gravity.ToString(), Gravity), @@ -103,13 +94,11 @@ namespace ml_prm ms_category.CreateEntry(ModSetting.RecoverDelay.ToString(), RecoverDelay), ms_category.CreateEntry(ModSetting.Slipperiness.ToString(), Slipperiness), ms_category.CreateEntry(ModSetting.Bounciness.ToString(), Bounciness), - ms_category.CreateEntry(ModSetting.ViewVelocity.ToString(), ViewVelocity), - ms_category.CreateEntry(ModSetting.VrFollow.ToString(), VrFollow) + ms_category.CreateEntry(ModSetting.ViewVelocity.ToString(), ViewVelocity) }; Hotkey = (bool)ms_entries[(int)ModSetting.Hotkey].BoxedValue; VelocityMultiplier = Mathf.Clamp((float)ms_entries[(int)ModSetting.VelocityMultiplier].BoxedValue, 1f, 50f); - RestorePosition = (bool)ms_entries[(int)ModSetting.RestorePosition].BoxedValue; MovementDrag = Mathf.Clamp((float)ms_entries[(int)ModSetting.MovementDrag].BoxedValue, 0f, 50f); AngularDrag = Mathf.Clamp((float)ms_entries[(int)ModSetting.MovementDrag].BoxedValue, 0f, 50f); Gravity = (bool)ms_entries[(int)ModSetting.Gravity].BoxedValue; @@ -121,7 +110,6 @@ namespace ml_prm Slipperiness = (bool)ms_entries[(int)ModSetting.Slipperiness].BoxedValue; Bounciness = (bool)ms_entries[(int)ModSetting.Bounciness].BoxedValue; ViewVelocity = (bool)ms_entries[(int)ModSetting.ViewVelocity].BoxedValue; - VrFollow = (bool)ms_entries[(int)ModSetting.VrFollow].BoxedValue; if(MelonLoader.MelonMod.RegisteredMelons.FirstOrDefault(m => m.Info.Name == "BTKUILib") != null) { @@ -141,9 +129,6 @@ namespace ml_prm ms_uiElements.Add(l_categoryMod.AddToggle("Use hotkey", "Switch ragdoll mode with 'R' key", Hotkey)); (ms_uiElements[(int)UiElementIndex.Hotkey] as BTKUILib.UIObjects.Components.ToggleButton).OnValueUpdated += (state) => OnToggleUpdate(ModSetting.Hotkey, state); - ms_uiElements.Add(l_categoryMod.AddToggle("Restore position", "Bring avatar back where ragdoll state was activated", RestorePosition)); - (ms_uiElements[(int)UiElementIndex.RestorePosition] as BTKUILib.UIObjects.Components.ToggleButton).OnValueUpdated += (state) => OnToggleUpdate(ModSetting.RestorePosition, state); - ms_uiElements.Add(l_categoryMod.AddToggle("Use gravity", "Apply gravity to ragdoll", Gravity)); (ms_uiElements[(int)UiElementIndex.Gravity] as BTKUILib.UIObjects.Components.ToggleButton).OnValueUpdated += (state) => OnToggleUpdate(ModSetting.Gravity, state); @@ -168,9 +153,6 @@ namespace ml_prm ms_uiElements.Add(l_categoryMod.AddToggle("View direction velocity", "Apply velocity to camera view direction", ViewVelocity)); (ms_uiElements[(int)UiElementIndex.ViewVelocity] as BTKUILib.UIObjects.Components.ToggleButton).OnValueUpdated += (state) => OnToggleUpdate(ModSetting.ViewVelocity, state); - ms_uiElements.Add(l_categoryMod.AddToggle("VR camera follow", "Forces VR camera to follow ragdoll", VrFollow)); - (ms_uiElements[(int)UiElementIndex.VrFollow] as BTKUILib.UIObjects.Components.ToggleButton).OnValueUpdated += (state) => OnToggleUpdate( ModSetting.VrFollow, state); - ms_uiElements.Add(l_page.AddSlider("Velocity multiplier", "Velocity multiplier upon entering ragdoll state", VelocityMultiplier, 1f, 50f)); (ms_uiElements[(int)UiElementIndex.VelocityMultiplier] as BTKUILib.UIObjects.Components.SliderFloat).OnValueUpdated += (value) => OnSliderUpdate(ModSetting.VelocityMultiplier, value); @@ -197,13 +179,6 @@ namespace ml_prm } break; - case ModSetting.RestorePosition: - { - RestorePosition = p_state; - RestorePositionChange?.Invoke(p_state); - } - break; - case ModSetting.Gravity: { Gravity = p_state; @@ -252,12 +227,6 @@ namespace ml_prm ViewVelocity = p_state; ViewVelocityChange?.Invoke(p_state); } break; - - case ModSetting.VrFollow: - { - VrFollow = p_state; - VrFollowChange?.Invoke(p_state); - } break; } ms_entries[(int)p_setting].BoxedValue = p_state; @@ -302,7 +271,6 @@ namespace ml_prm static void Reset() { OnToggleUpdate(ModSetting.Hotkey, true, UiElementIndex.Hotkey); - OnToggleUpdate(ModSetting.RestorePosition, false, UiElementIndex.RestorePosition); OnToggleUpdate(ModSetting.Gravity, true, UiElementIndex.Gravity); OnToggleUpdate(ModSetting.PointersReaction, true, UiElementIndex.PointersReaction); OnToggleUpdate(ModSetting.IgnoreLocal, true, UiElementIndex.IgnoreLocal); @@ -311,7 +279,6 @@ namespace ml_prm OnToggleUpdate(ModSetting.Slipperiness, false, UiElementIndex.Slipperiness); OnToggleUpdate(ModSetting.Bounciness, false, UiElementIndex.Bounciness); OnToggleUpdate(ModSetting.ViewVelocity, false, UiElementIndex.ViewVelocity); - OnToggleUpdate(ModSetting.VrFollow, true, UiElementIndex.VrFollow); OnSliderUpdate(ModSetting.VelocityMultiplier, 2f, UiElementIndex.VelocityMultiplier); OnSliderUpdate(ModSetting.MovementDrag, 2f, UiElementIndex.MovementDrag); OnSliderUpdate(ModSetting.AngularDrag, 2f, UiElementIndex.AngularDrag);