-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update Kinematics to slightly fix jittering + fixing code up a bit more
- Loading branch information
Showing
1 changed file
with
36 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,54 @@ | ||
using Epic.OnlineServices; | ||
using Epic.OnlineServices.Presence; | ||
using HarmonyLib; | ||
using TABGVR.Player; | ||
using UltimateIK; | ||
using UnityEngine; | ||
|
||
namespace TABGVR.Patches; | ||
|
||
[HarmonyPatch(typeof(Holding), nameof(Holding.LateUpdate))] | ||
[HarmonyPatch(typeof(Holding))] | ||
class KinematicsPatch | ||
{ | ||
static void Postfix(Holding __instance) | ||
static void SetupConnection(Rigidbody joint) | ||
{ | ||
joint.GetComponentInChildren<Collider>().enabled = false; | ||
|
||
// disable gravity in arms | ||
joint.useGravity = false; | ||
joint.transform.parent.Find(joint.gameObject.name).GetComponent<Rigidbody>().useGravity = false; | ||
} | ||
|
||
static void UpdateConnection(Rigidbody joint, GameObject controller) | ||
{ | ||
var controllerRelativeToGameCamera = controller.transform.position - Controllers.Head.transform.position + | ||
Camera.current.transform.position; | ||
|
||
if (Vector3.Distance(joint.position, controllerRelativeToGameCamera) < 0.01f) return; | ||
|
||
joint.MovePosition(joint.position + controllerRelativeToGameCamera - | ||
joint.transform.GetChild(0).position); | ||
} | ||
|
||
[HarmonyPatch(nameof(Holding.Start))] | ||
[HarmonyPostfix] | ||
static void StartPostfix(Holding __instance) | ||
{ | ||
SetupConnection(__instance.rightHand); | ||
SetupConnection(__instance.leftHand); | ||
} | ||
|
||
[HarmonyPatch(nameof(Holding.Update))] | ||
[HarmonyPostfix] | ||
static void UpdatePostfix(Holding __instance) | ||
{ | ||
if (!Controllers.LeftHand || !Controllers.RightHand || !Controllers.Head) return; | ||
if (__instance.player != global::Player.localPlayer) return; | ||
|
||
// Plugin.Logger.LogInfo( | ||
// $"KP {__instance.player} / Head: {Controllers.Head.transform.position} / Left: {Controllers.LeftHand.transform.position} / Right: {Controllers.RightHand.transform.position}"); | ||
|
||
__instance.rightHand.GetComponentInChildren<Collider>().enabled = false; | ||
__instance.leftHand.GetComponentInChildren<Collider>().enabled = false; | ||
|
||
__instance.rightHand.MovePosition(__instance.rightHand.position + Controllers.RightHand.transform.position - | ||
Controllers.Head.transform.position + | ||
Camera.current.transform.position - | ||
__instance.rightHand.transform.GetChild(0).position); | ||
|
||
__instance.leftHand.MovePosition(__instance.leftHand.position + Controllers.LeftHand.transform.position - | ||
Controllers.Head.transform.position + | ||
Camera.current.transform.position - | ||
__instance.leftHand.transform.GetChild(0).position); | ||
UpdateConnection(__instance.rightHand, Controllers.RightHand); | ||
UpdateConnection(__instance.leftHand, Controllers.LeftHand); | ||
} | ||
} |