mirror of
https://github.com/NotAKidoS/NAK_CVR_Mods.git
synced 2025-09-01 05:49:23 +00:00
48 lines
No EOL
1.4 KiB
C#
48 lines
No EOL
1.4 KiB
C#
using NAK.AlternateIKSystem.IK.WeightManipulators;
|
|
using RootMotion.FinalIK;
|
|
using UnityEngine;
|
|
|
|
namespace NAK.AlternateIKSystem.IK.IKHandlers;
|
|
|
|
internal class IKHandlerHalfBody : IKHandler
|
|
{
|
|
public IKHandlerHalfBody(VRIK vrik)
|
|
{
|
|
_vrik = vrik;
|
|
_solver = vrik.solver;
|
|
}
|
|
|
|
#region Game Overrides
|
|
|
|
public override void OnInitializeIk()
|
|
{
|
|
_vrik.onPreSolverUpdate.AddListener(OnPreSolverUpdateHalfBody);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region VRIK Solver Events
|
|
|
|
private void OnPreSolverUpdateHalfBody()
|
|
{
|
|
_solver.plantFeet = ModSettings.EntryPlantFeet.Value;
|
|
|
|
// Make root heading follow within a set limit
|
|
if (ModSettings.EntryBodyHeadingLimit.Value > 0)
|
|
{
|
|
float weightedAngleLimit = ModSettings.EntryBodyHeadingLimit.Value * _solver.locomotion.weight;
|
|
float currentRotation = IKManager.Instance.GetPlayerRotation().y;
|
|
float deltaAngleRoot = Mathf.DeltaAngle(currentRotation, _ikSimulatedRootAngle);
|
|
|
|
if (Mathf.Abs(deltaAngleRoot) > weightedAngleLimit)
|
|
{
|
|
deltaAngleRoot = Mathf.Sign(deltaAngleRoot) * weightedAngleLimit;
|
|
_ikSimulatedRootAngle = Mathf.MoveTowardsAngle(_ikSimulatedRootAngle, currentRotation, Mathf.Abs(deltaAngleRoot) - weightedAngleLimit);
|
|
}
|
|
|
|
_solver.spine.rootHeadingOffset = deltaAngleRoot;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
} |