Skip to content

Commit

Permalink
Fix fishes (and leviathans) movement
Browse files Browse the repository at this point in the history
  • Loading branch information
tornac1234 authored and dartasen committed Jan 5, 2025
1 parent 52f20eb commit ad49f35
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
11 changes: 8 additions & 3 deletions NitroxClient/MonoBehaviours/RemotelyControlled.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,23 @@ public void UpdateOrientation(Vector3 position, Quaternion rotation)
smoothRotation.Target = rotation;
}

public void UpdateKnownSplineUser(Vector3 currentPosition, Quaternion currentRotation, Vector3 destination, Vector3 desinationDirection, float velocity)
public void UpdateKnownSplineUser(Vector3 currentPosition, Quaternion currentRotation, Vector3 destination, Vector3 destinationDirection, float velocity)
{
TeleportIfTooFar(currentPosition, currentRotation);

if (swimBehaviour)
{
swimBehaviour.SwimToInternal(destination, desinationDirection, velocity, false);
// First lines of SwimBehaviour.SwimToInternal
swimBehaviour.originalTargetPosition = destination;
swimBehaviour.originalTargetDirection = destinationDirection;
swimBehaviour.originalVelocity = velocity;
// Only the useful part of the methods called in SwimBehaviour.SwimToInternal
swimBehaviour.splineFollowing.GoTo(destination, destinationDirection, velocity);
}

if (walkBehaviour)
{
walkBehaviour.GoToInternal(destination, desinationDirection, velocity);
walkBehaviour.GoToInternal(destination, destinationDirection, velocity);
}
}

Expand Down
18 changes: 18 additions & 0 deletions NitroxPatcher/Patches/Dynamic/SwimBehaviour_ManagedUpdate_Patch.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System.Reflection;
using NitroxClient.MonoBehaviours;
using NitroxModel.Helper;

namespace NitroxPatcher.Patches.Dynamic;

/// <summary>
/// Prevents <see cref="SwimBehaviour.ManagedUpdate"/> from happening on remotely controlled fishes (so their remote trajectory isn not modified)
/// </summary>
public sealed partial class SwimBehaviour_ManagedUpdate_Patch : NitroxPatch, IDynamicPatch
{
private static readonly MethodInfo TARGET_METHOD = Reflect.Method((SwimBehaviour t) => t.ManagedUpdate());

public static bool Prefix(SwimBehaviour __instance)
{
return !__instance.GetComponent<RemotelyControlled>();
}
}

0 comments on commit ad49f35

Please sign in to comment.