From a2ce54f2fe46902f544bfa9d30b8114939a029c7 Mon Sep 17 00:00:00 2001 From: SDraw Date: Thu, 20 Oct 2022 00:53:56 +0300 Subject: [PATCH] IK override while jumping --- README.md | 2 +- ml_amt/Main.cs | 1 + ml_amt/MotionTweaker.cs | 24 ++++++++++++++++++++---- ml_amt/Properties/AssemblyInfo.cs | 6 +++--- ml_amt/README.md | 1 + ml_amt/Settings.cs | 16 ++++++++++++++++ ml_amt/resources/menu.js | 7 +++++++ 7 files changed, 49 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index f567cb0..cae1245 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ Merged set of MelonLoader mods for ChilloutVR. | Full name | Short name | Latest version | Available in [CVRMA](https://github.com/knah/CVRMelonAssistant) | Current Status | Notes | |-----------|------------|----------------|-----------------------------------------------------------------|----------------|-------| | Avatar Change Info | ml_aci | 1.0.3 | Yes | Working | -| Avatar Motion Tweaker | ml_amt | 1.1.4 | On review | Working | +| Avatar Motion Tweaker | ml_amt | 1.1.5 | On review | Working | | Desktop Head Tracking | ml_dht | 1.0.7 | On review | Working | | Desktop Reticle Switch | ml_drs | 1.0.0 | Yes | Working | | Four Point Tracking | ml_fpt | 1.0.9 | On review | Working | diff --git a/ml_amt/Main.cs b/ml_amt/Main.cs index 69966dc..8093c37 100644 --- a/ml_amt/Main.cs +++ b/ml_amt/Main.cs @@ -43,6 +43,7 @@ System.Collections.IEnumerator WaitForLocalPlayer() m_localTweaker.SetPoseTransitions(Settings.PoseTransitions); m_localTweaker.SetAdjustedMovement(Settings.AdjustedMovement); m_localTweaker.SetIKOverrideFly(Settings.IKOverrideFly); + m_localTweaker.SetIKOverrideJump(Settings.IKOverrideJump); m_localTweaker.SetDetectEmotes(Settings.DetectEmotes); } diff --git a/ml_amt/MotionTweaker.cs b/ml_amt/MotionTweaker.cs index 4299e8a..c79e352 100644 --- a/ml_amt/MotionTweaker.cs +++ b/ml_amt/MotionTweaker.cs @@ -53,6 +53,7 @@ enum PoseState bool m_compatibleAvatar = false; float m_upright = 1f; PoseState m_poseState = PoseState.Standing; + bool m_grounded = false; bool m_ikOverrideCrouch = true; float m_crouchLimit = 0.65f; @@ -65,6 +66,7 @@ enum PoseState bool m_poseTransitions = true; bool m_adjustedMovement = true; bool m_ikOverrideFly = true; + bool m_ikOverrideJump = true; bool m_customLocomotionOffset = false; Vector3 m_locomotionOffset = Vector3.zero; @@ -78,7 +80,7 @@ public MotionTweaker() { m_parameters = new List(); } - + void Start() { Settings.IKOverrideCrouchChange += this.SetIKOverrideCrouch; @@ -88,9 +90,10 @@ void Start() Settings.PoseTransitionsChange += this.SetPoseTransitions; Settings.AdjustedMovementChange += this.SetAdjustedMovement; Settings.IKOverrideFlyChange += this.SetIKOverrideFly; + Settings.IKOverrideJumpChange += this.SetIKOverrideJump; Settings.DetectEmotesChange += this.SetDetectEmotes; } - + void OnDestroy() { Settings.IKOverrideCrouchChange -= this.SetIKOverrideCrouch; @@ -100,6 +103,7 @@ void OnDestroy() Settings.PoseTransitionsChange -= this.SetPoseTransitions; Settings.AdjustedMovementChange -= this.SetAdjustedMovement; Settings.IKOverrideFlyChange -= this.SetIKOverrideFly; + Settings.IKOverrideJumpChange -= this.SetIKOverrideJump; Settings.DetectEmotesChange -= this.SetDetectEmotes; } @@ -107,6 +111,8 @@ void Update() { if(m_avatarReady) { + m_grounded = (bool)ms_groundedRaw.GetValue(MovementSystem.Instance); + // Update upright Matrix4x4 l_hmdMatrix = PlayerSetup.Instance.transform.GetMatrix().inverse * (PlayerSetup.Instance._inVr ? PlayerSetup.Instance.vrHeadTracker.transform.GetMatrix() : PlayerSetup.Instance.desktopCameraRig.transform.GetMatrix()); float l_currentHeight = Mathf.Clamp((l_hmdMatrix * ms_pointVector).y, 0f, float.MaxValue); @@ -179,10 +185,10 @@ void Update() switch(l_param.m_sync) { case ParameterSyncType.Local: - PlayerSetup.Instance._animator.SetBool(l_param.m_hash, (bool)ms_groundedRaw.GetValue(MovementSystem.Instance)); + PlayerSetup.Instance._animator.SetBool(l_param.m_hash, m_grounded); break; case ParameterSyncType.Synced: - PlayerSetup.Instance.animatorManager.SetAnimatorParameterBool(l_param.m_name, (bool)ms_groundedRaw.GetValue(MovementSystem.Instance)); + PlayerSetup.Instance.animatorManager.SetAnimatorParameterBool(l_param.m_name, m_grounded); break; } } @@ -197,6 +203,7 @@ public void OnAvatarClear() { m_vrIk = null; m_locomotionLayer = -1; + m_grounded = false; m_avatarReady = false; m_compatibleAvatar = false; m_poseState = PoseState.Standing; @@ -275,6 +282,7 @@ void OnIKPreUpdate() if(m_detectEmotes && m_emoteActive) m_vrIk.solver.IKPositionWeight = 0f; + // Game manages VRIK for desktop itself if(PlayerSetup.Instance._inVr) { if((m_ikOverrideCrouch && (m_poseState != PoseState.Standing)) || (m_ikOverrideProne && (m_poseState == PoseState.Proning))) @@ -282,6 +290,10 @@ void OnIKPreUpdate() if(m_ikOverrideFly && MovementSystem.Instance.flying) m_vrIk.solver.locomotion.weight = 0f; } + + // But not this + if(m_ikOverrideJump && !m_grounded && !MovementSystem.Instance.flying) + m_vrIk.solver.locomotion.weight = 0f; } void OnIKPostUpdate() @@ -332,6 +344,10 @@ public void SetIKOverrideFly(bool p_state) { m_ikOverrideFly = p_state; } + public void SetIKOverrideJump(bool p_state) + { + m_ikOverrideJump = p_state; + } public void SetDetectEmotes(bool p_state) { m_detectEmotes = p_state; diff --git a/ml_amt/Properties/AssemblyInfo.cs b/ml_amt/Properties/AssemblyInfo.cs index 55fcc54..e7136d0 100644 --- a/ml_amt/Properties/AssemblyInfo.cs +++ b/ml_amt/Properties/AssemblyInfo.cs @@ -1,10 +1,10 @@ using System.Reflection; [assembly: AssemblyTitle("AvatarMotionTweaker")] -[assembly: AssemblyVersion("1.1.4")] -[assembly: AssemblyFileVersion("1.1.4")] +[assembly: AssemblyVersion("1.1.6")] +[assembly: AssemblyFileVersion("1.1.6")] -[assembly: MelonLoader.MelonInfo(typeof(ml_amt.AvatarMotionTweaker), "AvatarMotionTweaker", "1.1.4", "SDraw", "https://github.com/SDraw/ml_mods_cvr")] +[assembly: MelonLoader.MelonInfo(typeof(ml_amt.AvatarMotionTweaker), "AvatarMotionTweaker", "1.1.6", "SDraw", "https://github.com/SDraw/ml_mods_cvr")] [assembly: MelonLoader.MelonGame(null, "ChilloutVR")] [assembly: MelonLoader.MelonPlatform(MelonLoader.MelonPlatformAttribute.CompatiblePlatforms.WINDOWS_X64)] [assembly: MelonLoader.MelonPlatformDomain(MelonLoader.MelonPlatformDomainAttribute.CompatibleDomains.MONO)] \ No newline at end of file diff --git a/ml_amt/README.md b/ml_amt/README.md index cc15265..63ad380 100644 --- a/ml_amt/README.md +++ b/ml_amt/README.md @@ -17,6 +17,7 @@ Available mod's settings in `Settings - Implementation - Avatar Motion Tweaker`: * **Prone limit:** defines prone limit; default value - `30`. * Note: Can be overrided by avatar. For this avatar has to have child gameobject with name `ProneLimit`, its Y-axis location will be used as limit, should be in range [0.0, 1.0]. * **IK override while flying:** disables legs locomotion/autostep in fly mode; default value - `true`. +* **IK override while jumping:** disables legs locomotion/autostep in jump; default value - `true`. * **Pose transitions:** allows regular avatars animator to transit in crouch/prone states; default value - `true`. * Note: Avatar is considered as regular if its AAS animator doesn't have `Upright` parameter. * **Adjusted pose movement speed:** scales movement speed upon crouching/proning; default value - `true`. diff --git a/ml_amt/Settings.cs b/ml_amt/Settings.cs index 6dcea47..210e57e 100644 --- a/ml_amt/Settings.cs +++ b/ml_amt/Settings.cs @@ -16,6 +16,7 @@ enum ModSetting PoseTransitions, AdjustedMovement, IKOverrideFly, + IKOverrideJump, DetectEmotes }; @@ -26,6 +27,7 @@ enum ModSetting static bool ms_poseTransitions = true; static bool ms_adjustedMovement = true; static bool ms_ikOverrideFly = true; + static bool ms_ikOverrideJump = true; static bool ms_detectEmotes = true; static MelonLoader.MelonPreferences_Category ms_category = null; @@ -38,6 +40,7 @@ enum ModSetting static public event Action PoseTransitionsChange; static public event Action AdjustedMovementChange; static public event Action IKOverrideFlyChange; + static public event Action IKOverrideJumpChange; static public event Action DetectEmotesChange; public static void Init() @@ -52,6 +55,7 @@ public static void Init() ms_entries.Add(ms_category.CreateEntry(ModSetting.PoseTransitions.ToString(), true)); ms_entries.Add(ms_category.CreateEntry(ModSetting.AdjustedMovement.ToString(), true)); ms_entries.Add(ms_category.CreateEntry(ModSetting.IKOverrideFly.ToString(), true)); + ms_entries.Add(ms_category.CreateEntry(ModSetting.IKOverrideJump.ToString(), true)); ms_entries.Add(ms_category.CreateEntry(ModSetting.DetectEmotes.ToString(), true)); Load(); @@ -90,6 +94,7 @@ static void Load() ms_poseTransitions = (bool)ms_entries[(int)ModSetting.PoseTransitions].BoxedValue; ms_adjustedMovement = (bool)ms_entries[(int)ModSetting.AdjustedMovement].BoxedValue; ms_ikOverrideFly = (bool)ms_entries[(int)ModSetting.IKOverrideFly].BoxedValue; + ms_ikOverrideJump = (bool)ms_entries[(int)ModSetting.IKOverrideJump].BoxedValue; ms_detectEmotes = (bool)ms_entries[(int)ModSetting.DetectEmotes].BoxedValue; } @@ -159,6 +164,13 @@ static void OnToggleUpdate(string p_name, string p_value) } break; + case ModSetting.IKOverrideJump: + { + ms_ikOverrideJump = bool.Parse(p_value); + IKOverrideJumpChange?.Invoke(ms_ikOverrideJump); + } + break; + case ModSetting.DetectEmotes: { ms_detectEmotes = bool.Parse(p_value); @@ -199,6 +211,10 @@ public static bool IKOverrideFly { get => ms_ikOverrideFly; } + public static bool IKOverrideJump + { + get => ms_ikOverrideJump; + } public static bool DetectEmotes { get => ms_detectEmotes; diff --git a/ml_amt/resources/menu.js b/ml_amt/resources/menu.js index c9f6275..c54e3c8 100644 --- a/ml_amt/resources/menu.js +++ b/ml_amt/resources/menu.js @@ -215,6 +215,13 @@ function inp_toggle_mod_amt(_obj, _callbackName) { +
+
IK override while jumping:
+
+
+
+
+
Pose transitions: