@@ -1720,7 +1720,15 @@ internal NetworkTransformState LocalAuthoritativeNetworkState
17201720 // Non-Authoritative's current position, scale, and rotation that is used to assure the non-authoritative side cannot make adjustments to
17211721 // the portions of the transform being synchronized.
17221722 private Vector3 m_InternalCurrentPosition ;
1723- private Vector3 m_TargetPosition ;
1723+
1724+ /// <summary>
1725+ /// Used primarily to track the last state received that had a change in position.
1726+ /// When interpolation is disabled, this value is applied immediately to the transform.
1727+ /// When interpolation is enabled, this value is only updated in the event that if
1728+ /// interpolation is disabled the last known state position update will be continually applied.
1729+ /// This might not be the exact
1730+ /// </summary>
1731+ private Vector3 m_LastStateTargetPosition ;
17241732 private Vector3 m_InternalCurrentScale ;
17251733 private Vector3 m_TargetScale ;
17261734 private Quaternion m_InternalCurrentRotation ;
@@ -2555,12 +2563,12 @@ private void OnNetworkTick(bool isCalledFromParent = false)
25552563 var transformSource = transform ;
25562564 OnUpdateAuthoritativeState ( ref transformSource , isCalledFromParent ) ;
25572565#if COM_UNITY_MODULES_PHYSICS || COM_UNITY_MODULES_PHYSICS2D
2558- m_InternalCurrentPosition = m_TargetPosition = m_UseRigidbodyForMotion ? m_NetworkRigidbodyInternal . GetPosition ( ) : GetSpaceRelativePosition ( ) ;
2566+ m_InternalCurrentPosition = m_LastStateTargetPosition = m_UseRigidbodyForMotion ? m_NetworkRigidbodyInternal . GetPosition ( ) : GetSpaceRelativePosition ( ) ;
25592567 m_InternalCurrentRotation = m_UseRigidbodyForMotion ? m_NetworkRigidbodyInternal . GetRotation ( ) : GetSpaceRelativeRotation ( ) ;
25602568 m_TargetRotation = m_InternalCurrentRotation . eulerAngles ;
25612569#else
25622570 m_InternalCurrentPosition = GetSpaceRelativePosition ( ) ;
2563- m_TargetPosition = GetSpaceRelativePosition ( ) ;
2571+ m_LastStateTargetPosition = GetSpaceRelativePosition ( ) ;
25642572#endif
25652573 }
25662574 else // If we are no longer authority, unsubscribe to the tick event
@@ -2719,7 +2727,7 @@ protected internal void ApplyAuthoritativeState()
27192727 {
27202728 if ( networkState . HasPositionChange && SynchronizePosition )
27212729 {
2722- adjustedPosition = m_TargetPosition ;
2730+ adjustedPosition = m_LastStateTargetPosition ;
27232731 }
27242732
27252733 if ( networkState . HasScaleChange && SynchronizeScale )
@@ -2947,7 +2955,7 @@ private void ApplyTeleportingState(NetworkTransformState newState)
29472955 }
29482956
29492957 m_InternalCurrentPosition = currentPosition ;
2950- m_TargetPosition = currentPosition ;
2958+ m_LastStateTargetPosition = currentPosition ;
29512959
29522960 // Apply the position
29532961 if ( newState . InLocalSpace )
@@ -3117,6 +3125,7 @@ internal void ApplyUpdatedState(NetworkTransformState newState)
31173125 // Only if using half float precision and our position had changed last update then
31183126 if ( UseHalfFloatPrecision && m_LocalAuthoritativeNetworkState . HasPositionChange )
31193127 {
3128+ // Do a full precision synchronization to apply the base position and offset.
31203129 if ( m_LocalAuthoritativeNetworkState . SynchronizeBaseHalfFloat )
31213130 {
31223131 m_HalfPositionState = m_LocalAuthoritativeNetworkState . NetworkDeltaPosition ;
@@ -3130,9 +3139,10 @@ internal void ApplyUpdatedState(NetworkTransformState newState)
31303139 // This is to assure when you get the position of the state it is the correct position
31313140 m_LocalAuthoritativeNetworkState . NetworkDeltaPosition . ToVector3 ( 0 ) ;
31323141 }
3133- // Update our target position
3134- m_TargetPosition = m_HalfPositionState . ToVector3 ( newState . NetworkTick ) ;
3135- m_LocalAuthoritativeNetworkState . CurrentPosition = m_TargetPosition ;
3142+ // Update the target position for this incoming state.
3143+ // This becomes the last known received state position (unlike interpolators that will have a queue).
3144+ m_LastStateTargetPosition = m_HalfPositionState . ToVector3 ( newState . NetworkTick ) ;
3145+ m_LocalAuthoritativeNetworkState . CurrentPosition = m_LastStateTargetPosition ;
31363146 }
31373147
31383148 if ( ! Interpolate )
@@ -3148,9 +3158,9 @@ internal void ApplyUpdatedState(NetworkTransformState newState)
31483158 {
31493159 // If interpolating, get the current value as the final next position or current position
31503160 // depending upon if the interpolator is still processing a state or not.
3151- var newTargetPosition = Interpolate ? m_PositionInterpolator . GetInterpolatedValue ( ) : m_TargetPosition ;
31523161 if ( ! m_LocalAuthoritativeNetworkState . UseHalfFloatPrecision )
31533162 {
3163+ var newTargetPosition = Interpolate ? m_PositionInterpolator . GetInterpolatedValue ( ) : m_LastStateTargetPosition ;
31543164 var position = m_LocalAuthoritativeNetworkState . GetPosition ( ) ;
31553165 if ( m_LocalAuthoritativeNetworkState . HasPositionX )
31563166 {
@@ -3166,9 +3176,10 @@ internal void ApplyUpdatedState(NetworkTransformState newState)
31663176 {
31673177 newTargetPosition . z = position . z ;
31683178 }
3179+ m_LastStateTargetPosition = newTargetPosition ;
31693180 }
3170- m_TargetPosition = newTargetPosition ;
3171- UpdatePositionInterpolator ( m_TargetPosition , sentTime ) ;
3181+
3182+ UpdatePositionInterpolator ( m_LastStateTargetPosition , sentTime ) ;
31723183 }
31733184
31743185 if ( m_LocalAuthoritativeNetworkState . HasScaleChange )
@@ -3739,7 +3750,7 @@ private void InternalInitialization(bool isOwnershipChange = false)
37393750 }
37403751
37413752 m_InternalCurrentPosition = currentPosition ;
3742- m_TargetPosition = currentPosition ;
3753+ m_LastStateTargetPosition = currentPosition ;
37433754
37443755 RegisterForTickUpdate ( this ) ;
37453756
@@ -3764,7 +3775,7 @@ private void InternalInitialization(bool isOwnershipChange = false)
37643775 DeregisterForTickUpdate ( this ) ;
37653776 ResetInterpolatedStateToCurrentAuthoritativeState ( ) ;
37663777 m_InternalCurrentPosition = currentPosition ;
3767- m_TargetPosition = currentPosition ;
3778+ m_LastStateTargetPosition = currentPosition ;
37683779 m_InternalCurrentScale = transform . localScale ;
37693780 m_TargetScale = transform . localScale ;
37703781 m_InternalCurrentRotation = currentRotation ;
@@ -3857,7 +3868,7 @@ private void DefaultParentChanged(NetworkObject parentNetworkObject)
38573868 var position = GetSpaceRelativePosition ( ) ;
38583869 var rotation = GetSpaceRelativeRotation ( ) ;
38593870#endif
3860- m_TargetPosition = m_InternalCurrentPosition = position ;
3871+ m_LastStateTargetPosition = m_InternalCurrentPosition = position ;
38613872 m_InternalCurrentRotation = rotation ;
38623873 m_TargetRotation = m_InternalCurrentRotation . eulerAngles ;
38633874 m_TargetScale = m_InternalCurrentScale = GetScale ( ) ;
@@ -3905,7 +3916,7 @@ internal override void InternalOnNetworkObjectParentChanged(NetworkObject parent
39053916
39063917 if ( LastTickSync == m_LocalAuthoritativeNetworkState . GetNetworkTick ( ) )
39073918 {
3908- m_InternalCurrentPosition = m_TargetPosition = GetSpaceRelativePosition ( ) ;
3919+ m_InternalCurrentPosition = m_LastStateTargetPosition = GetSpaceRelativePosition ( ) ;
39093920 m_PositionInterpolator . ResetTo ( m_PositionInterpolator . Parent , m_InternalCurrentPosition , NetworkManager . ServerTime . Time ) ;
39103921 if ( InLocalSpace )
39113922 {
@@ -3924,7 +3935,7 @@ internal override void InternalOnNetworkObjectParentChanged(NetworkObject parent
39243935 }
39253936 else
39263937 {
3927- m_InternalCurrentPosition = m_TargetPosition = Interpolate ? m_PositionInterpolator . GetInterpolatedValue ( ) : GetSpaceRelativePosition ( ) ;
3938+ m_InternalCurrentPosition = m_LastStateTargetPosition = Interpolate ? m_PositionInterpolator . GetInterpolatedValue ( ) : GetSpaceRelativePosition ( ) ;
39283939 }
39293940 }
39303941 }
0 commit comments