Skip to content

Commit 5a56eef

Browse files
fix
Set the target parent when initializing. Added additional checks when getting the current interpolated value to handle the interpolation frames between the current and next measurement states.
1 parent b9a3a10 commit 5a56eef

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

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

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ private void ConvertTransformSpace()
296296
{
297297
if (InterpolateState.TargetParent != null)
298298
{
299-
// Convert to world space.
299+
// Convert to world space or local space depending upon what our current parent is.
300300
ConvertInterpolateStateValues(InterpolateState.TargetParent, false);
301301
}
302302

@@ -316,7 +316,7 @@ private void InternalReset(Transform parent, T targetValue, double serverTime, b
316316

317317
// Set our initial value (what we will interpolate from relative to the next state update received)
318318
InterpolateState.Reset(currentValue);
319-
319+
InterpolateState.TargetParent = parent;
320320
if (addMeasurement)
321321
{
322322
// Add the first measurement for our baseline
@@ -686,7 +686,22 @@ internal void AddMeasurement(Transform parent, T newMeasurement, double sentTime
686686
[MethodImpl(MethodImplOptions.AggressiveInlining)]
687687
public T GetInterpolatedValue()
688688
{
689-
return InterpolateState.CurrentValue;
689+
var currentValue = InterpolateState.CurrentValue;
690+
if (AutoConvertTransformSpace && InterpolateState.TargetParent != Parent)
691+
{
692+
// Just convert on the fly until the next state is reached where it will do a full
693+
// conversion when popped from the queue.
694+
if (InterpolateState.TargetParent != null)
695+
{
696+
currentValue = OnConvertTransformSpace(InterpolateState.TargetParent, currentValue, false);
697+
}
698+
699+
if (Parent != null)
700+
{
701+
currentValue = OnConvertTransformSpace(Parent, currentValue, true);
702+
}
703+
}
704+
return currentValue;
690705
}
691706

692707
/// <summary>

0 commit comments

Comments
 (0)