fix desktop thrusting

This commit is contained in:
NotAKidoS 2023-03-29 04:00:42 -05:00
parent b71bff051c
commit 04d9152d9c
2 changed files with 21 additions and 65 deletions

View file

@ -166,9 +166,12 @@ internal class DesktopVRIKSystem : MonoBehaviour
float _initialStepHeight; float _initialStepHeight;
// Player Info // Player Info
Transform _cameraTransform; Transform _cameraTransform = null;
bool _isEmotePlaying; bool _isEmotePlaying = false;
float _simulatedRootAngle; float _simulatedRootAngle = 0f;
float _locomotionWeight = 1f;
float _locomotionWeightLerp = 1f;
float _locomotionLerpSpeed = 10f;
// Last Movement Parent Info // Last Movement Parent Info
Vector3 _previousPosition; Vector3 _previousPosition;
@ -196,37 +199,13 @@ internal class DesktopVRIKSystem : MonoBehaviour
if (avatarVRIK == null) return; if (avatarVRIK == null) return;
HandleLocomotionTracking(); HandleLocomotionTracking();
LerpLocomotionWeight();
ApplyBodySystemWeights(); ApplyBodySystemWeights();
} }
void HandleLocomotionTracking() void HandleLocomotionTracking()
{ {
bool isMoving = movementSystem.movementVector.magnitude > 0f; bool isMoving = movementSystem.movementVector.magnitude > 0f;
// AvatarMotionTweaker handles VRIK a bit better than DesktopVRIK
if (Setting_IntegrationAMT && DesktopVRIKMod.integration_AMT)
{
if (isMoving)
{
if (BodySystem.TrackingLocomotionEnabled)
{
BodySystem.TrackingLocomotionEnabled = false;
avatarIKSolver.Reset();
ResetDesktopVRIK();
}
}
else
{
if (!BodySystem.TrackingLocomotionEnabled)
{
BodySystem.TrackingLocomotionEnabled = true;
avatarIKSolver.Reset();
ResetDesktopVRIK();
}
}
return;
}
bool isGrounded = movementSystem._isGrounded; bool isGrounded = movementSystem._isGrounded;
bool isCrouching = movementSystem.crouching; bool isCrouching = movementSystem.crouching;
bool isProne = movementSystem.prone; bool isProne = movementSystem.prone;
@ -256,6 +235,12 @@ internal class DesktopVRIKSystem : MonoBehaviour
} }
} }
void LerpLocomotionWeight()
{
_locomotionWeight = BodySystem.TrackingEnabled && BodySystem.TrackingLocomotionEnabled ? 1.0f : 0.0f;
_locomotionWeightLerp = Mathf.Lerp(_locomotionWeightLerp, _locomotionWeight, Time.deltaTime * _locomotionLerpSpeed);
}
void ApplyBodySystemWeights() void ApplyBodySystemWeights()
{ {
void SetArmWeight(IKSolverVR.Arm arm, bool isTracked) void SetArmWeight(IKSolverVR.Arm arm, bool isTracked)
@ -274,7 +259,7 @@ internal class DesktopVRIKSystem : MonoBehaviour
{ {
avatarVRIK.enabled = true; avatarVRIK.enabled = true;
avatarIKSolver.IKPositionWeight = BodySystem.TrackingPositionWeight; avatarIKSolver.IKPositionWeight = BodySystem.TrackingPositionWeight;
avatarIKSolver.locomotion.weight = BodySystem.TrackingLocomotionEnabled ? 1f : 0f; avatarIKSolver.locomotion.weight = _locomotionWeight;
SetArmWeight(avatarIKSolver.leftArm, BodySystem.TrackingLeftArmEnabled && avatarIKSolver.leftArm.target != null); SetArmWeight(avatarIKSolver.leftArm, BodySystem.TrackingLeftArmEnabled && avatarIKSolver.leftArm.target != null);
SetArmWeight(avatarIKSolver.rightArm, BodySystem.TrackingRightArmEnabled && avatarIKSolver.rightArm.target != null); SetArmWeight(avatarIKSolver.rightArm, BodySystem.TrackingRightArmEnabled && avatarIKSolver.rightArm.target != null);
@ -324,19 +309,15 @@ internal class DesktopVRIKSystem : MonoBehaviour
{ {
if (avatarVRIK == null) return; if (avatarVRIK == null) return;
bool changed = isEmotePlaying != _isEmotePlaying; if (isEmotePlaying == _isEmotePlaying) return;
if (!changed) return;
_isEmotePlaying = isEmotePlaying; _isEmotePlaying = isEmotePlaying;
avatarTransform.localPosition = Vector3.zero;
avatarTransform.localRotation = Quaternion.identity;
if (avatarLookAtIK != null) if (avatarLookAtIK != null)
avatarLookAtIK.enabled = !isEmotePlaying; avatarLookAtIK.enabled = !isEmotePlaying;
// Disable tracking completely while emoting
BodySystem.TrackingEnabled = !isEmotePlaying; BodySystem.TrackingEnabled = !isEmotePlaying;
avatarIKSolver.Reset(); avatarIKSolver.Reset();
ResetDesktopVRIK(); ResetDesktopVRIK();
} }
@ -372,26 +353,19 @@ internal class DesktopVRIKSystem : MonoBehaviour
public void OnPreSolverUpdate() public void OnPreSolverUpdate()
{ {
if (_isEmotePlaying) return;
bool isGrounded = movementSystem._isGrounded;
// Calculate weight
float weight = avatarIKSolver.IKPositionWeight;
weight *= 1f - movementSystem.movementVector.magnitude;
weight *= isGrounded ? 1f : 0f;
// Reset avatar offset // Reset avatar offset
avatarTransform.localPosition = Vector3.zero; avatarTransform.localPosition = Vector3.zero;
avatarTransform.localRotation = Quaternion.identity; avatarTransform.localRotation = Quaternion.identity;
if (_isEmotePlaying) return;
// Set plant feet // Set plant feet
avatarIKSolver.plantFeet = Setting_PlantFeet; avatarIKSolver.plantFeet = Setting_PlantFeet;
// Emulate old VRChat hip movementSystem // Emulate old VRChat hip movementSystem
if (Setting_BodyLeanWeight > 0) if (Setting_BodyLeanWeight > 0)
{ {
float weightedAngle = Setting_BodyLeanWeight * weight; float weightedAngle = Setting_BodyLeanWeight * _locomotionWeightLerp;
float angle = _cameraTransform.localEulerAngles.x; float angle = _cameraTransform.localEulerAngles.x;
angle = angle > 180 ? angle - 360 : angle; angle = angle > 180 ? angle - 360 : angle;
Quaternion rotation = Quaternion.AngleAxis(angle * weightedAngle, avatarTransform.right); Quaternion rotation = Quaternion.AngleAxis(angle * weightedAngle, avatarTransform.right);
@ -401,7 +375,7 @@ internal class DesktopVRIKSystem : MonoBehaviour
// Make root heading follow within a set limit // Make root heading follow within a set limit
if (Setting_BodyHeadingLimit > 0) if (Setting_BodyHeadingLimit > 0)
{ {
float weightedAngleLimit = Setting_BodyHeadingLimit * weight; float weightedAngleLimit = Setting_BodyHeadingLimit * _locomotionWeightLerp;
float deltaAngleRoot = Mathf.DeltaAngle(transform.eulerAngles.y, _simulatedRootAngle); float deltaAngleRoot = Mathf.DeltaAngle(transform.eulerAngles.y, _simulatedRootAngle);
float absDeltaAngleRoot = Mathf.Abs(deltaAngleRoot); float absDeltaAngleRoot = Mathf.Abs(deltaAngleRoot);
if (absDeltaAngleRoot > weightedAngleLimit) if (absDeltaAngleRoot > weightedAngleLimit)

View file

@ -33,11 +33,6 @@ public class DesktopVRIKMod : MelonMod
public static readonly MelonPreferences_Entry<float> EntryChestHeadingWeight = public static readonly MelonPreferences_Entry<float> EntryChestHeadingWeight =
CategoryDesktopVRIK.CreateEntry("Chest Heading Weight", 0.75f, description: "Determines how much the chest will face the Body Heading Limit. Set to 0 to align with head."); CategoryDesktopVRIK.CreateEntry("Chest Heading Weight", 0.75f, description: "Determines how much the chest will face the Body Heading Limit. Set to 0 to align with head.");
public static readonly MelonPreferences_Entry<bool> EntryIntegrationAMT =
CategoryDesktopVRIK.CreateEntry("AMT Integration", true, description: "Relies on AvatarMotionTweaker to handle VRIK Locomotion weights if available.");
public static bool integration_AMT = false;
public override void OnInitializeMelon() public override void OnInitializeMelon()
{ {
Logger = LoggerInstance; Logger = LoggerInstance;
@ -52,16 +47,6 @@ public class DesktopVRIKMod : MelonMod
Logger.Msg("Initializing BTKUILib support."); Logger.Msg("Initializing BTKUILib support.");
BTKUIAddon.Init(); BTKUIAddon.Init();
} }
//AvatarMotionTweaker Handling
if (MelonMod.RegisteredMelons.Any(it => it.Info.Name == "AvatarMotionTweaker"))
{
Logger.Msg("AvatarMotionTweaker was found. Relying on it to handle VRIK locomotion.");
integration_AMT = true;
}
else
{
Logger.Msg("AvatarMotionTweaker was not found. Using built-in VRIK locomotion handling.");
}
} }
internal static void UpdateAllSettings() internal static void UpdateAllSettings()
@ -79,9 +64,6 @@ public class DesktopVRIKMod : MelonMod
// Calibration Settings // Calibration Settings
DesktopVRIKSystem.Instance.Setting_UseVRIKToes = EntryUseVRIKToes.Value; DesktopVRIKSystem.Instance.Setting_UseVRIKToes = EntryUseVRIKToes.Value;
DesktopVRIKSystem.Instance.Setting_FindUnmappedToes = EntryFindUnmappedToes.Value; DesktopVRIKSystem.Instance.Setting_FindUnmappedToes = EntryFindUnmappedToes.Value;
// Integration Settings
DesktopVRIKSystem.Instance.Setting_IntegrationAMT = EntryIntegrationAMT.Value;
} }
void OnUpdateSettings(object arg1, object arg2) => UpdateAllSettings(); void OnUpdateSettings(object arg1, object arg2) => UpdateAllSettings();