UseReliableRpc for ship/raft when ur inside/riding

This commit is contained in:
JohnCorby 2022-08-24 14:11:43 -07:00
parent 00b5c4a4f2
commit f9dfb2e871
2 changed files with 8 additions and 5 deletions

View File

@ -10,7 +10,9 @@ namespace QSB.EchoesOfTheEye.RaftSync.TransformSync;
public class RaftTransformSync : UnsectoredRigidbodySync, ILinkedNetworkBehaviour
{
protected override bool UseInterpolation => Locator.GetPlayerController().GetGroundBody() != AttachedRigidbody;
private bool IsRidingRaft => Locator.GetPlayerController() && Locator.GetPlayerController().GetGroundBody() == AttachedRigidbody;
protected override bool UseInterpolation => !IsRidingRaft;
protected override bool UseReliableRpc => IsRidingRaft;
private float _lastSetPositionTime;
private const float ForcePositionAfterTime = 1;
@ -77,8 +79,7 @@ public class RaftTransformSync : UnsectoredRigidbodySync, ILinkedNetworkBehaviou
var targetPos = ReferenceTransform.FromRelPos(UseInterpolation ? SmoothPosition : transform.position);
var targetRot = ReferenceTransform.FromRelRot(UseInterpolation ? SmoothRotation : transform.rotation);
var onRaft = Locator.GetPlayerController().GetGroundBody() == AttachedRigidbody;
if (onRaft)
if (IsRidingRaft)
{
if (Time.unscaledTime >= _lastSetPositionTime + ForcePositionAfterTime)
{

View File

@ -59,7 +59,7 @@ public class ShipTransformSync : SectoredRigidbodySync
var targetPos = ReferenceTransform.FromRelPos(UseInterpolation ? SmoothPosition : transform.position);
var targetRot = ReferenceTransform.FromRelRot(UseInterpolation ? SmoothRotation : transform.rotation);
if (PlayerState.IsInsideShip())
if (IsInsideShip)
{
if (Time.unscaledTime >= _lastSetPositionTime + ForcePositionAfterTime)
{
@ -98,5 +98,7 @@ public class ShipTransformSync : SectoredRigidbodySync
rigidbody._currentVelocity = newVelocity;
}
protected override bool UseInterpolation => !PlayerState.IsInsideShip();
private static bool IsInsideShip => PlayerState.IsInsideShip();
protected override bool UseInterpolation => !IsInsideShip;
protected override bool UseReliableRpc => IsInsideShip;
}