Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Runtime.CompilerServices;
using UnityEngine;


namespace Unity.Netcode.Components
{
/// <summary>
Expand Down Expand Up @@ -571,7 +572,7 @@ private void InternalMoveRotation2D(Quaternion rotation)
{
var quaternion = Quaternion.identity;
var angles = quaternion.eulerAngles;
angles.z = m_InternalRigidbody2D.rotation;
angles.z = rotation.z;
quaternion.eulerAngles = angles;
m_InternalRigidbody2D.MoveRotation(quaternion);
}
Expand Down Expand Up @@ -845,6 +846,28 @@ public void SetIsKinematic(bool isKinematic)
PostSetIsKinematic();
}


[MethodImpl(MethodImplOptions.AggressiveInlining)]
private bool HasInterpolationTypeSet(InterpolationTypes interpolationType)
{
#if COM_UNITY_MODULES_PHYSICS && COM_UNITY_MODULES_PHYSICS2D
if (m_IsRigidbody2D)
{
return interpolationType == InterpolationTypes.Extrapolate ? m_InternalRigidbody2D.interpolation == RigidbodyInterpolation2D.Extrapolate : m_InternalRigidbody2D.interpolation == RigidbodyInterpolation2D.Interpolate;
}
else
{
return interpolationType == InterpolationTypes.Extrapolate ? m_InternalRigidbody.interpolation == RigidbodyInterpolation.Extrapolate : m_InternalRigidbody.interpolation == RigidbodyInterpolation.Interpolate;
}
#endif
#if COM_UNITY_MODULES_PHYSICS && !COM_UNITY_MODULES_PHYSICS2D
return interpolationType == InterpolationTypes.Extrapolate ? m_InternalRigidbody2D.interpolation == RigidbodyInterpolation2D.Extrapolate : m_InternalRigidbody2D.interpolation == RigidbodyInterpolation2D.Interpolate;
#endif
#if !COM_UNITY_MODULES_PHYSICS && COM_UNITY_MODULES_PHYSICS2D
return interpolationType == InterpolationTypes.Extrapolate ? m_InternalRigidbody.interpolation == RigidbodyInterpolation.Extrapolate : m_InternalRigidbody.interpolation == RigidbodyInterpolation.Interpolate;
#endif
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void PostSetIsKinematic()
{
Expand All @@ -853,26 +876,29 @@ private void PostSetIsKinematic()
{
return;
}

if (UseRigidBodyForMotion)
{
// Only if the NetworkTransform is set to interpolate do we need to check for extrapolation
if (NetworkTransform.Interpolate && m_OriginalInterpolation == InterpolationTypes.Extrapolate)
// Exit early if the original interpolation type is not set to extrapolate or NetworkTransform interpolate is disabled
if (m_OriginalInterpolation != InterpolationTypes.Extrapolate || !NetworkTransform.Interpolate)
{
if (IsKinematic())
{
// If not already set to interpolate then set the Rigidbody to interpolate
if (m_InternalRigidbody.interpolation == RigidbodyInterpolation.Extrapolate)
{
// Sleep until the next fixed update when switching from extrapolation to interpolation
SleepRigidbody();
SetInterpolation(InterpolationTypes.Interpolate);
}
}
else
{
// Switch it back to the original interpolation if non-kinematic (doesn't require sleep).
SetInterpolation(m_OriginalInterpolation);
}
return;
}

// Otherwise, if this is the active physics object
if (!IsKinematic())
{
// switch it back to the original interpolation and exit early
SetInterpolation(m_OriginalInterpolation);
return;
}

// If the Rigidbody or Rigidbody2D is currently configured to extrapolate
if (HasInterpolationTypeSet(InterpolationTypes.Extrapolate))
{
// sleep until the next fixed update when switching from extrapolation to interpolation
SleepRigidbody();
SetInterpolation(InterpolationTypes.Interpolate);
}
}
else
Expand Down
Loading
Loading