Skip to content

Commit

Permalink
IK override while jumping
Browse files Browse the repository at this point in the history
  • Loading branch information
SDraw committed Oct 19, 2022
1 parent fd48185 commit a2ce54f
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
1 change: 1 addition & 0 deletions ml_amt/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
24 changes: 20 additions & 4 deletions ml_amt/MotionTweaker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -78,7 +80,7 @@ public MotionTweaker()
{
m_parameters = new List<AdditionalParameterInfo>();
}

void Start()
{
Settings.IKOverrideCrouchChange += this.SetIKOverrideCrouch;
Expand All @@ -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;
Expand All @@ -100,13 +103,16 @@ void OnDestroy()
Settings.PoseTransitionsChange -= this.SetPoseTransitions;
Settings.AdjustedMovementChange -= this.SetAdjustedMovement;
Settings.IKOverrideFlyChange -= this.SetIKOverrideFly;
Settings.IKOverrideJumpChange -= this.SetIKOverrideJump;
Settings.DetectEmotesChange -= this.SetDetectEmotes;
}

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);
Expand Down Expand Up @@ -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;
}
}
Expand All @@ -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;
Expand Down Expand Up @@ -275,13 +282,18 @@ 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)))
m_vrIk.solver.locomotion.weight = 0f;
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()
Expand Down Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions ml_amt/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -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)]
1 change: 1 addition & 0 deletions ml_amt/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
16 changes: 16 additions & 0 deletions ml_amt/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ enum ModSetting
PoseTransitions,
AdjustedMovement,
IKOverrideFly,
IKOverrideJump,
DetectEmotes
};

Expand All @@ -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;
Expand All @@ -38,6 +40,7 @@ enum ModSetting
static public event Action<bool> PoseTransitionsChange;
static public event Action<bool> AdjustedMovementChange;
static public event Action<bool> IKOverrideFlyChange;
static public event Action<bool> IKOverrideJumpChange;
static public event Action<bool> DetectEmotesChange;

public static void Init()
Expand All @@ -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();
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
7 changes: 7 additions & 0 deletions ml_amt/resources/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,13 @@ function inp_toggle_mod_amt(_obj, _callbackName) {
</div>
</div>
<div class ="row-wrapper">
<div class ="option-caption">IK override while jumping: </div>
<div class ="option-input">
<div id="IKOverrideJump" class ="inp_toggle no-scroll" data-current="true"></div>
</div>
</div>
<div class ="row-wrapper">
<div class ="option-caption">Pose transitions: </div>
<div class ="option-input">
Expand Down

0 comments on commit a2ce54f

Please sign in to comment.