mirror of
https://github.com/NotAKidoS/NAK_CVR_Mods.git
synced 2025-09-04 23:39:22 +00:00
[DesktopVRIK] Fixes for r173
This commit is contained in:
parent
0d4e6e6331
commit
892ff611b5
8 changed files with 72 additions and 23 deletions
|
@ -1,4 +1,5 @@
|
|||
using ABI.CCK.Components;
|
||||
using ABI_RC.Core.InteractionSystem;
|
||||
using ABI.CCK.Components;
|
||||
using ABI_RC.Systems.IK.SubSystems;
|
||||
using NAK.DesktopVRIK.IK.VRIKHelpers;
|
||||
using RootMotion.FinalIK;
|
||||
|
@ -143,10 +144,10 @@ internal abstract class IKHandler
|
|||
{
|
||||
_ikSimulatedRootAngle = _vrik.transform.eulerAngles.y;
|
||||
|
||||
_solver.Reset();
|
||||
|
||||
if(ModSettings.EntryResetFootstepsOnIdle.Value)
|
||||
VRIKUtils.ResetToInitialFootsteps(_vrik, _locomotionData, _scaleDifference);
|
||||
|
||||
_solver.Reset();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
|
|
@ -107,10 +107,11 @@ internal class IKHandlerDesktop : IKHandler
|
|||
bool isProne = MovementSystem.Instance.prone;
|
||||
bool isFlying = MovementSystem.Instance.flying;
|
||||
bool isSitting = MovementSystem.Instance.sitting;
|
||||
bool isSwimming = MovementSystem.Instance.GetSubmerged();
|
||||
bool isStanding = PlayerSetup.Instance.avatarUpright >=
|
||||
Mathf.Max(PlayerSetup.Instance.avatarProneLimit, PlayerSetup.Instance.avatarCrouchLimit);
|
||||
|
||||
return !(isMoving || isCrouching || isProne || isFlying || isSitting || !isGrounded || !isStanding);
|
||||
return !(isMoving || isCrouching || isProne || isFlying || isSwimming || isSitting || !isGrounded || !isStanding);
|
||||
}
|
||||
|
||||
private void ResetSolverIfNeeded()
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
using ABI_RC.Core.Player;
|
||||
using ABI_RC.Core.Savior;
|
||||
using ABI_RC.Systems.IK.SubSystems;
|
||||
using ABI_RC.Systems.MovementSystem;
|
||||
using NAK.DesktopVRIK.IK.IKHandlers;
|
||||
using NAK.DesktopVRIK.IK.VRIKHelpers;
|
||||
using RootMotion.FinalIK;
|
||||
|
@ -29,7 +30,7 @@ public class IKManager : MonoBehaviour
|
|||
|
||||
// Avatar Info
|
||||
private Animator _animator;
|
||||
private Transform _hipTransform;
|
||||
internal Transform _hipTransform;
|
||||
|
||||
// Animator Info
|
||||
private int _animLocomotionLayer = -1;
|
||||
|
@ -38,9 +39,9 @@ public class IKManager : MonoBehaviour
|
|||
private const string _ikposeLayerName = "IKPose";
|
||||
|
||||
// Pose Info
|
||||
private HumanPoseHandler _humanPoseHandler;
|
||||
private HumanPose _humanPose;
|
||||
private HumanPose _humanPoseInitial;
|
||||
internal HumanPoseHandler _humanPoseHandler;
|
||||
internal HumanPose _humanPose;
|
||||
internal HumanPose _humanPoseInitial;
|
||||
|
||||
#endregion
|
||||
|
||||
|
@ -127,6 +128,8 @@ public class IKManager : MonoBehaviour
|
|||
if (_ikHandler == null)
|
||||
return false;
|
||||
|
||||
DesktopVRIK.Logger.Msg(scaleDifference);
|
||||
|
||||
_ikHandler.OnPlayerScaled(scaleDifference);
|
||||
return true;
|
||||
}
|
||||
|
@ -204,6 +207,7 @@ public class IKManager : MonoBehaviour
|
|||
|
||||
VRIKUtils.ApplyScaleToVRIK(_vrik, _ikHandler._locomotionData, 1f);
|
||||
_vrik.onPreSolverUpdate.AddListener(OnPreSolverUpdateGeneral);
|
||||
_vrik.onPreSolverUpdate.AddListener(OnPreSolverUpdateDesktopSwimming);
|
||||
_vrik.onPostSolverUpdate.AddListener(OnPostSolverUpdateGeneral);
|
||||
}
|
||||
|
||||
|
@ -240,6 +244,35 @@ public class IKManager : MonoBehaviour
|
|||
|
||||
#region VRIK Solver Events General
|
||||
|
||||
private void OnPreSolverUpdateDesktopSwimming()
|
||||
{
|
||||
if (_solver.IKPositionWeight < 0.9f)
|
||||
return;
|
||||
|
||||
Vector3 headPosition = _animator.GetBoneTransform(HumanBodyBones.Head).position;
|
||||
|
||||
// rotate hips around head bone to simulate diving
|
||||
if (MovementSystem.Instance._playerIsSubmerged)
|
||||
{
|
||||
const float maxAngleForward = 85f;
|
||||
const float maxAngleBackward = -85f;
|
||||
|
||||
float lookAngle = _desktopCamera.localEulerAngles.x;
|
||||
if (lookAngle > 180) lookAngle -= 360;
|
||||
|
||||
lookAngle = Mathf.Clamp(lookAngle, maxAngleBackward, maxAngleForward);
|
||||
float multiplier = Mathf.Lerp(0f, 1f, (MovementSystem.Instance.movementVector.magnitude - 0.5f) * 2f); // blend in when moving w/ sprint
|
||||
multiplier *= (-1f * MovementSystem.Instance.GetDepth()); // blend out when at surface
|
||||
|
||||
_solver.IKPositionWeight = 1f - (-1f * multiplier); // disable IK completely when fast swimming (only applicable to DesktopVRIK)
|
||||
_hipTransform.RotateAround(headPosition, _animator.transform.right, lookAngle * multiplier);
|
||||
}
|
||||
|
||||
// offset avatar hips so head bone is centered on avatar root
|
||||
// this fixes animations becoming scrunched up once VRIK solves!
|
||||
_hipTransform.position -= (headPosition - _animator.transform.position) with { y = 0f };
|
||||
}
|
||||
|
||||
private void OnPreSolverUpdateGeneral()
|
||||
{
|
||||
if (_solver.IKPositionWeight < 0.9f)
|
||||
|
|
|
@ -39,9 +39,9 @@ public static class VRIKUtils
|
|||
|
||||
// hack, use parent transform instead as setting feet position moves root (root.parent), but does not work for VR
|
||||
var footsteps = vrik.solver.locomotion.footsteps;
|
||||
footsteps[0].Reset(rootWorldRot, root.TransformPoint(locomotionData.InitialFootPosLeft * scaleModifier),
|
||||
footsteps[0].Reset(rootWorldRot, root.TransformPoint(locomotionData.InitialFootPosLeft),
|
||||
rootWorldRot * locomotionData.InitialFootRotLeft);
|
||||
footsteps[1].Reset(rootWorldRot, root.TransformPoint(locomotionData.InitialFootPosRight * scaleModifier),
|
||||
footsteps[1].Reset(rootWorldRot, root.TransformPoint(locomotionData.InitialFootPosRight),
|
||||
rootWorldRot * locomotionData.InitialFootRotRight);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue