Skip to content

Commit

Permalink
Fix player animation execution order errors
Browse files Browse the repository at this point in the history
  • Loading branch information
DaXcess committed Sep 17, 2024
1 parent 685600d commit 3416f9a
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 34 deletions.
41 changes: 31 additions & 10 deletions Source/Networking/VRNetPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ namespace LCVR.Networking;
/// <summary>
/// A behaviour that is attached to other VR players
/// </summary>
[DefaultExecutionOrder(-100)]
public class VRNetPlayer : MonoBehaviour
{
private GameObject playerGhost;
Expand Down Expand Up @@ -171,6 +170,9 @@ private void Awake()
else
component.enabled = true;
}

// Create a "prefix" script that runs before other game scripts
gameObject.AddComponent<VRNetPlayerEarly>();
}

private void BuildVRRig()
Expand Down Expand Up @@ -247,6 +249,8 @@ private void BuildVRRig()

private void Update()
{
UpdateIKWeights();

// Apply crouch offset
crouchOffset = Mathf.Lerp(crouchOffset, crouchState switch
{
Expand Down Expand Up @@ -295,8 +299,6 @@ private void Update()

private void LateUpdate()
{
UpdateBones();

var positionOffset = new Vector3(0, crouchState switch
{
CrouchState.Roomscale => 0.1f,
Expand Down Expand Up @@ -370,14 +372,8 @@ private void LateUpdate()
if (StartOfRound.Instance.localPlayerController.localVisorTargetPoint is not null)
usernameBillboard.LookAt(StartOfRound.Instance.localPlayerController.localVisorTargetPoint);
}

private void UpdateBones()
{
Bones.ServerItemHolder.localPosition = new Vector3(0.002f, 0.056f, -0.046f);
Bones.ServerItemHolder.localRotation = Quaternion.identity;
}

public void UpdateIKWeights()
private void UpdateIKWeights()
{
// Constants
PlayerController.cameraLookRig1.weight = 0.45f;
Expand Down Expand Up @@ -566,6 +562,31 @@ public class PlayerData
{
public bool DisableSteeringWheel { get; set; }
}

/// <summary>
/// A script for remote VR players that runs before other scripts in the game
/// </summary>
[DefaultExecutionOrder(-100)]
private class VRNetPlayerEarly : MonoBehaviour
{
private VRNetPlayer player;

private void Awake()
{
player = GetComponent<VRNetPlayer>();
}

private void LateUpdate()
{
UpdateBones();
}

private void UpdateBones()
{
player.Bones.ServerItemHolder.localPosition = new Vector3(0.002f, 0.056f, -0.046f);
player.Bones.ServerItemHolder.localRotation = Quaternion.identity;
}
}
}

[Serialize]
Expand Down
23 changes: 1 addition & 22 deletions Source/Patches/PlayerControllerPatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ static Vector3 GetClampedCameraPosition(PlayerControllerB player)
}

/// <summary>
/// Allow interacting with items even when we're inside of a special menu
/// Allow interacting with items even when we're inside a special menu
/// </summary>
[HarmonyPatch(typeof(PlayerControllerB), nameof(PlayerControllerB.ActivateItem_performed))]
[HarmonyTranspiler]
Expand All @@ -377,27 +377,6 @@ private static IEnumerable<CodeInstruction> AllowActivateDuringMenu(IEnumerable<
[HarmonyPatch]
internal static class UniversalPlayerControllerPatches
{
/// <summary>
/// Prevent the use of the secondary arm rigs, so that VR arms still freely move when inside the Company Cruiser
/// </summary>
[HarmonyPatch(typeof(PlayerControllerB), nameof(PlayerControllerB.Update))]
[HarmonyPostfix]
private static void KeepRigConstraints(PlayerControllerB __instance)
{
// Handle IK for local player
if (VRSession.InVR && __instance.IsLocalPlayer() && VRSession.Instance is {} session)
{
session.LocalPlayer.UpdateIKWeights();
return;
}

// Handle IK for remote player
if (NetworkSystem.Instance.TryGetPlayer((ushort)__instance.playerClientId, out var player))
{
player.UpdateIKWeights();
}
}

/// <summary>
/// Disable the EnterLadder animation to fix some clunkyness with holding items
/// </summary>
Expand Down
4 changes: 3 additions & 1 deletion Source/Player/VRPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,8 @@ private void ResetHeight_performed(InputAction.CallbackContext obj)

private void Update()
{
UpdateIKWeights();

// Make sure the XR Origin has the same parent as the player
if (xrOrigin.parent != transform.parent)
{
Expand Down Expand Up @@ -720,7 +722,7 @@ private void OnDestroy()
Actions.Instance["Reset Height"].performed -= ResetHeight_performed;
}

public void UpdateIKWeights()
private void UpdateIKWeights()
{
// Constants
PlayerController.cameraLookRig1.weight = 0.45f;
Expand Down
2 changes: 1 addition & 1 deletion Source/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class Plugin : BaseUnityPlugin
{
public const string PLUGIN_GUID = "io.daxcess.lcvr";
public const string PLUGIN_NAME = "LCVR";
public const string PLUGIN_VERSION = "1.3.3";
public const string PLUGIN_VERSION = "1.3.4";

#if DEBUG
private const string SKIP_CHECKSUM_VAR = $"--lcvr-skip-checksum={PLUGIN_VERSION}-dev";
Expand Down

0 comments on commit 3416f9a

Please sign in to comment.