Skip to content

Commit e5dc365

Browse files
update
Minor adjustment to smooth dampening.
1 parent a5d9bf8 commit e5dc365

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

com.unity.netcode.gameobjects/Runtime/Components/Interpolator/BufferedLinearInterpolator.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@ private void TryConsumeFromBuffer(double renderTime, float minDeltaTime, float m
279279
// TODO: We might consider creating yet another queue to add these items to and assure that the time is accelerated
280280
// for each item as opposed to losing the resolution of the values.
281281
InterpolateState.TimeToTargetValue = Mathf.Clamp((float)(target.TimeSent - startTime), minDeltaTime, maxDeltaTime);
282+
282283
InterpolateState.Target = target;
283284
}
284285
InterpolateState.ResetDelta();
@@ -321,11 +322,11 @@ public T Update(float deltaTime, double tickLatencyAsTime, float minDeltaTime, f
321322
// Smooth dampen our current time
322323
var current = SmoothDamp(InterpolateState.CurrentValue, InterpolateState.Target.Value.Item, ref m_RateOfChange, InterpolateState.TimeToTargetValue, InterpolateState.DeltaTime);
323324
// Smooth dampen a predicted time based on our average delta time
324-
var predict = SmoothDamp(InterpolateState.CurrentValue, InterpolateState.Target.Value.Item, ref m_PredictedRateOfChange, InterpolateState.TimeToTargetValue, InterpolateState.DeltaTime + InterpolateState.AverageDeltaTime);
325-
// Split the difference between the two.
325+
var predict = SmoothDamp(InterpolateState.CurrentValue, InterpolateState.Target.Value.Item, ref m_PredictedRateOfChange, InterpolateState.TimeToTargetValue, InterpolateState.DeltaTime + (InterpolateState.AverageDeltaTime * 2));
326+
// Lerp between the current and predicted.
326327
// Note: Since smooth dampening cannot over shoot, both current and predict will eventually become the same or will be very close to the same.
327328
// Upon stopping motion, the final resing value should be a very close aproximation of the authority side.
328-
InterpolateState.CurrentValue = Interpolate(current, predict, 0.5f);
329+
InterpolateState.CurrentValue = Interpolate(current, predict, deltaTime);
329330
}
330331
m_NbItemsReceivedThisFrame = 0;
331332
return InterpolateState.CurrentValue;

com.unity.netcode.gameobjects/Runtime/Components/NetworkTransform.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3786,8 +3786,10 @@ private void UpdateInterpolation()
37863786
}
37873787

37883788
var tickLatencyAsTime = m_CachedNetworkManager.LocalTime.TimeTicksAgo(tickLatency).Time;
3789+
// Smooth dampening specific:
3790+
// We clamp between tick rate and bit beyond the tick rate but not 2x tick rate (we predict 2x out)
37893791
var minDeltaTime = m_CachedNetworkManager.LocalTime.FixedDeltaTime;
3790-
var maxDeltaTime = (tickLatency * m_CachedNetworkManager.ServerTime.FixedDeltaTime);
3792+
var maxDeltaTime = (1.666667f * m_CachedNetworkManager.ServerTime.FixedDeltaTime);
37913793

37923794
// Now only update the interpolators for the portions of the transform being synchronized
37933795
if (SynchronizePosition)

0 commit comments

Comments
 (0)