@@ -1720,7 +1720,15 @@ internal NetworkTransformState LocalAuthoritativeNetworkState
1720
1720
// Non-Authoritative's current position, scale, and rotation that is used to assure the non-authoritative side cannot make adjustments to
1721
1721
// the portions of the transform being synchronized.
1722
1722
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 ;
1724
1732
private Vector3 m_InternalCurrentScale ;
1725
1733
private Vector3 m_TargetScale ;
1726
1734
private Quaternion m_InternalCurrentRotation ;
@@ -2555,12 +2563,12 @@ private void OnNetworkTick(bool isCalledFromParent = false)
2555
2563
var transformSource = transform ;
2556
2564
OnUpdateAuthoritativeState ( ref transformSource , isCalledFromParent ) ;
2557
2565
#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 ( ) ;
2559
2567
m_InternalCurrentRotation = m_UseRigidbodyForMotion ? m_NetworkRigidbodyInternal . GetRotation ( ) : GetSpaceRelativeRotation ( ) ;
2560
2568
m_TargetRotation = m_InternalCurrentRotation . eulerAngles ;
2561
2569
#else
2562
2570
m_InternalCurrentPosition = GetSpaceRelativePosition ( ) ;
2563
- m_TargetPosition = GetSpaceRelativePosition ( ) ;
2571
+ m_LastStateTargetPosition = GetSpaceRelativePosition ( ) ;
2564
2572
#endif
2565
2573
}
2566
2574
else // If we are no longer authority, unsubscribe to the tick event
@@ -2719,7 +2727,7 @@ protected internal void ApplyAuthoritativeState()
2719
2727
{
2720
2728
if ( networkState . HasPositionChange && SynchronizePosition )
2721
2729
{
2722
- adjustedPosition = m_TargetPosition ;
2730
+ adjustedPosition = m_LastStateTargetPosition ;
2723
2731
}
2724
2732
2725
2733
if ( networkState . HasScaleChange && SynchronizeScale )
@@ -2947,7 +2955,7 @@ private void ApplyTeleportingState(NetworkTransformState newState)
2947
2955
}
2948
2956
2949
2957
m_InternalCurrentPosition = currentPosition ;
2950
- m_TargetPosition = currentPosition ;
2958
+ m_LastStateTargetPosition = currentPosition ;
2951
2959
2952
2960
// Apply the position
2953
2961
if ( newState . InLocalSpace )
@@ -3117,6 +3125,7 @@ internal void ApplyUpdatedState(NetworkTransformState newState)
3117
3125
// Only if using half float precision and our position had changed last update then
3118
3126
if ( UseHalfFloatPrecision && m_LocalAuthoritativeNetworkState . HasPositionChange )
3119
3127
{
3128
+ // Do a full precision synchronization to apply the base position and offset.
3120
3129
if ( m_LocalAuthoritativeNetworkState . SynchronizeBaseHalfFloat )
3121
3130
{
3122
3131
m_HalfPositionState = m_LocalAuthoritativeNetworkState . NetworkDeltaPosition ;
@@ -3130,9 +3139,10 @@ internal void ApplyUpdatedState(NetworkTransformState newState)
3130
3139
// This is to assure when you get the position of the state it is the correct position
3131
3140
m_LocalAuthoritativeNetworkState . NetworkDeltaPosition . ToVector3 ( 0 ) ;
3132
3141
}
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 ;
3136
3146
}
3137
3147
3138
3148
if ( ! Interpolate )
@@ -3148,9 +3158,9 @@ internal void ApplyUpdatedState(NetworkTransformState newState)
3148
3158
{
3149
3159
// If interpolating, get the current value as the final next position or current position
3150
3160
// depending upon if the interpolator is still processing a state or not.
3151
- var newTargetPosition = Interpolate ? m_PositionInterpolator . GetInterpolatedValue ( ) : m_TargetPosition ;
3152
3161
if ( ! m_LocalAuthoritativeNetworkState . UseHalfFloatPrecision )
3153
3162
{
3163
+ var newTargetPosition = Interpolate ? m_PositionInterpolator . GetInterpolatedValue ( ) : m_LastStateTargetPosition ;
3154
3164
var position = m_LocalAuthoritativeNetworkState . GetPosition ( ) ;
3155
3165
if ( m_LocalAuthoritativeNetworkState . HasPositionX )
3156
3166
{
@@ -3166,9 +3176,10 @@ internal void ApplyUpdatedState(NetworkTransformState newState)
3166
3176
{
3167
3177
newTargetPosition . z = position . z ;
3168
3178
}
3179
+ m_LastStateTargetPosition = newTargetPosition ;
3169
3180
}
3170
- m_TargetPosition = newTargetPosition ;
3171
- UpdatePositionInterpolator ( m_TargetPosition , sentTime ) ;
3181
+
3182
+ UpdatePositionInterpolator ( m_LastStateTargetPosition , sentTime ) ;
3172
3183
}
3173
3184
3174
3185
if ( m_LocalAuthoritativeNetworkState . HasScaleChange )
@@ -3739,7 +3750,7 @@ private void InternalInitialization(bool isOwnershipChange = false)
3739
3750
}
3740
3751
3741
3752
m_InternalCurrentPosition = currentPosition ;
3742
- m_TargetPosition = currentPosition ;
3753
+ m_LastStateTargetPosition = currentPosition ;
3743
3754
3744
3755
RegisterForTickUpdate ( this ) ;
3745
3756
@@ -3764,7 +3775,7 @@ private void InternalInitialization(bool isOwnershipChange = false)
3764
3775
DeregisterForTickUpdate ( this ) ;
3765
3776
ResetInterpolatedStateToCurrentAuthoritativeState ( ) ;
3766
3777
m_InternalCurrentPosition = currentPosition ;
3767
- m_TargetPosition = currentPosition ;
3778
+ m_LastStateTargetPosition = currentPosition ;
3768
3779
m_InternalCurrentScale = transform . localScale ;
3769
3780
m_TargetScale = transform . localScale ;
3770
3781
m_InternalCurrentRotation = currentRotation ;
@@ -3857,7 +3868,7 @@ private void DefaultParentChanged(NetworkObject parentNetworkObject)
3857
3868
var position = GetSpaceRelativePosition ( ) ;
3858
3869
var rotation = GetSpaceRelativeRotation ( ) ;
3859
3870
#endif
3860
- m_TargetPosition = m_InternalCurrentPosition = position ;
3871
+ m_LastStateTargetPosition = m_InternalCurrentPosition = position ;
3861
3872
m_InternalCurrentRotation = rotation ;
3862
3873
m_TargetRotation = m_InternalCurrentRotation . eulerAngles ;
3863
3874
m_TargetScale = m_InternalCurrentScale = GetScale ( ) ;
@@ -3905,7 +3916,7 @@ internal override void InternalOnNetworkObjectParentChanged(NetworkObject parent
3905
3916
3906
3917
if ( LastTickSync == m_LocalAuthoritativeNetworkState . GetNetworkTick ( ) )
3907
3918
{
3908
- m_InternalCurrentPosition = m_TargetPosition = GetSpaceRelativePosition ( ) ;
3919
+ m_InternalCurrentPosition = m_LastStateTargetPosition = GetSpaceRelativePosition ( ) ;
3909
3920
m_PositionInterpolator . ResetTo ( m_PositionInterpolator . Parent , m_InternalCurrentPosition , NetworkManager . ServerTime . Time ) ;
3910
3921
if ( InLocalSpace )
3911
3922
{
@@ -3924,7 +3935,7 @@ internal override void InternalOnNetworkObjectParentChanged(NetworkObject parent
3924
3935
}
3925
3936
else
3926
3937
{
3927
- m_InternalCurrentPosition = m_TargetPosition = Interpolate ? m_PositionInterpolator . GetInterpolatedValue ( ) : GetSpaceRelativePosition ( ) ;
3938
+ m_InternalCurrentPosition = m_LastStateTargetPosition = Interpolate ? m_PositionInterpolator . GetInterpolatedValue ( ) : GetSpaceRelativePosition ( ) ;
3928
3939
}
3929
3940
}
3930
3941
}
0 commit comments