diff --git a/QSB/EchoesOfTheEye/RaftSync/TransformSync/RaftTransformSync.cs b/QSB/EchoesOfTheEye/RaftSync/TransformSync/RaftTransformSync.cs index 5950afa9..227f154b 100644 --- a/QSB/EchoesOfTheEye/RaftSync/TransformSync/RaftTransformSync.cs +++ b/QSB/EchoesOfTheEye/RaftSync/TransformSync/RaftTransformSync.cs @@ -75,32 +75,29 @@ public class RaftTransformSync : UnsectoredRigidbodySync, ILinkedNetworkBehaviou protected override void ApplyToAttached() { var targetPos = ReferenceTransform.FromRelPos(transform.position); + var targetRot = ReferenceTransform.FromRelRot(transform.rotation); - if (Time.unscaledTime >= _lastSetPositionTime + ForcePositionAfterTime) + var onRaft = Locator.GetPlayerController().GetGroundBody() == AttachedRigidbody; + if (onRaft) { - _lastSetPositionTime = Time.unscaledTime; - - var targetRot = ReferenceTransform.FromRelRot(transform.rotation); - - var onRaft = false; - var localPos = Vector3.zero; - var localRot = Quaternion.identity; - if (Locator.GetPlayerController().GetGroundBody() == AttachedRigidbody) + if (Time.unscaledTime >= _lastSetPositionTime + ForcePositionAfterTime) { - onRaft = true; - localPos = AttachedRigidbody.transform.InverseTransformPoint(Locator.GetPlayerTransform().position); - localRot = AttachedRigidbody.transform.InverseTransformRotation(Locator.GetPlayerTransform().rotation); - } + _lastSetPositionTime = Time.unscaledTime; + var relPos = AttachedRigidbody.transform.ToRelPos(Locator.GetPlayerTransform().position); + var relRot = AttachedRigidbody.transform.ToRelRot(Locator.GetPlayerTransform().rotation); + + AttachedRigidbody.SetPosition(targetPos); + AttachedRigidbody.SetRotation(targetRot); + + Locator.GetPlayerTransform().position = AttachedRigidbody.transform.FromRelPos(relPos); + Locator.GetPlayerTransform().rotation = AttachedRigidbody.transform.FromRelRot(relRot); + } + } + else + { AttachedRigidbody.SetPosition(targetPos); AttachedRigidbody.SetRotation(targetRot); - - if (onRaft) - { - var playerTransform = Locator.GetPlayerBody().transform; - playerTransform.position = AttachedRigidbody.transform.TransformPoint(localPos); - playerTransform.rotation = AttachedRigidbody.transform.TransformRotation(localRot); - } } var targetVelocity = ReferenceRigidbody.FromRelVel(Velocity, targetPos);