mirror of
https://github.com/hanetzer/sdraw_mods_cvr.git
synced 2025-09-05 03:19:23 +00:00
Locomotion center according to avatar scale
This commit is contained in:
parent
b0ae6082bf
commit
268fec558f
2 changed files with 34 additions and 3 deletions
|
@ -47,6 +47,11 @@ namespace ml_amt
|
||||||
null,
|
null,
|
||||||
new HarmonyLib.HarmonyMethod(typeof(AvatarMotionTweaker).GetMethod(nameof(OnCalibrate_Postfix), BindingFlags.Static | BindingFlags.NonPublic))
|
new HarmonyLib.HarmonyMethod(typeof(AvatarMotionTweaker).GetMethod(nameof(OnCalibrate_Postfix), BindingFlags.Static | BindingFlags.NonPublic))
|
||||||
);
|
);
|
||||||
|
HarmonyInstance.Patch(
|
||||||
|
typeof(PlayerSetup).GetMethod("SetPlaySpaceScale", BindingFlags.NonPublic | BindingFlags.Instance),
|
||||||
|
null,
|
||||||
|
new HarmonyLib.HarmonyMethod(typeof(AvatarMotionTweaker).GetMethod(nameof(OnPlayspaceScale_Postfix), BindingFlags.Static | BindingFlags.NonPublic))
|
||||||
|
);
|
||||||
|
|
||||||
// FBT detour
|
// FBT detour
|
||||||
HarmonyInstance.Patch(
|
HarmonyInstance.Patch(
|
||||||
|
@ -153,6 +158,20 @@ namespace ml_amt
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void OnPlayspaceScale_Postfix() => ms_instance?.OnPlayspaceScale();
|
||||||
|
void OnPlayspaceScale()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if(m_localTweaker != null)
|
||||||
|
m_localTweaker.OnPlayspaceScale();
|
||||||
|
}
|
||||||
|
catch(System.Exception l_exception)
|
||||||
|
{
|
||||||
|
MelonLoader.MelonLogger.Error(l_exception);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// FBT detection override
|
// FBT detection override
|
||||||
static void FBTDetour_Prefix()
|
static void FBTDetour_Prefix()
|
||||||
{
|
{
|
||||||
|
|
|
@ -116,8 +116,7 @@ namespace ml_amt
|
||||||
// Update upright
|
// Update upright
|
||||||
Matrix4x4 l_hmdMatrix = PlayerSetup.Instance.transform.GetMatrix().inverse * (m_inVR ? PlayerSetup.Instance.vrHeadTracker.transform.GetMatrix() : PlayerSetup.Instance.desktopCameraRig.transform.GetMatrix());
|
Matrix4x4 l_hmdMatrix = PlayerSetup.Instance.transform.GetMatrix().inverse * (m_inVR ? PlayerSetup.Instance.vrHeadTracker.transform.GetMatrix() : PlayerSetup.Instance.desktopCameraRig.transform.GetMatrix());
|
||||||
float l_currentHeight = Mathf.Clamp((l_hmdMatrix * ms_pointVector).y, 0f, float.MaxValue);
|
float l_currentHeight = Mathf.Clamp((l_hmdMatrix * ms_pointVector).y, 0f, float.MaxValue);
|
||||||
float l_avatarScale = (m_avatarScale > 0f) ? (PlayerSetup.Instance._avatar.transform.localScale.y / m_avatarScale) : 0f;
|
float l_avatarViewHeight = Mathf.Clamp(m_viewPointHeight * GetRelativeScale(), 0f, float.MaxValue);
|
||||||
float l_avatarViewHeight = Mathf.Clamp(m_viewPointHeight * l_avatarScale, 0f, float.MaxValue);
|
|
||||||
m_upright = Mathf.Clamp01((l_avatarViewHeight > 0f) ? (l_currentHeight / l_avatarViewHeight) : 0f);
|
m_upright = Mathf.Clamp01((l_avatarViewHeight > 0f) ? (l_currentHeight / l_avatarViewHeight) : 0f);
|
||||||
m_poseState = (m_upright <= Mathf.Min(m_proneLimit, m_crouchLimit)) ? PoseState.Proning : ((m_upright <= Mathf.Max(m_proneLimit, m_crouchLimit)) ? PoseState.Crouching : PoseState.Standing);
|
m_poseState = (m_upright <= Mathf.Min(m_proneLimit, m_crouchLimit)) ? PoseState.Proning : ((m_upright <= Mathf.Max(m_proneLimit, m_crouchLimit)) ? PoseState.Crouching : PoseState.Standing);
|
||||||
|
|
||||||
|
@ -273,6 +272,14 @@ namespace ml_amt
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal void OnPlayspaceScale()
|
||||||
|
{
|
||||||
|
if((m_vrIk != null) && Settings.MassCenter)
|
||||||
|
{
|
||||||
|
m_vrIk.solver.locomotion.offset = m_massCenter * GetRelativeScale();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void OnIKPreUpdate()
|
void OnIKPreUpdate()
|
||||||
{
|
{
|
||||||
bool l_legsOverride = false;
|
bool l_legsOverride = false;
|
||||||
|
@ -383,7 +390,12 @@ namespace ml_amt
|
||||||
public void SetMassCenter(bool p_state)
|
public void SetMassCenter(bool p_state)
|
||||||
{
|
{
|
||||||
if(m_vrIk != null)
|
if(m_vrIk != null)
|
||||||
m_vrIk.solver.locomotion.offset = (Settings.MassCenter ? m_massCenter : m_locomotionOffset);
|
m_vrIk.solver.locomotion.offset = (Settings.MassCenter ? (m_massCenter * GetRelativeScale()) : m_locomotionOffset);
|
||||||
|
}
|
||||||
|
|
||||||
|
float GetRelativeScale()
|
||||||
|
{
|
||||||
|
return ((m_avatarScale > 0f) ? (PlayerSetup.Instance._avatar.transform.localScale.y / m_avatarScale) : 0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
public float GetUpright() => m_upright;
|
public float GetUpright() => m_upright;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue