SmartSmoothDamp for rotation

This commit is contained in:
JohnCorby 2021-12-13 13:33:18 -08:00
parent adad302ba0
commit b0e15fb557
5 changed files with 11 additions and 6 deletions

View File

@ -137,7 +137,7 @@ namespace QSB.Syncs.Sectored.Rigidbodies
if (UseInterpolation)
{
positionToSet = SmartSmoothDamp(AttachedObject.GetPosition(), targetPos);
rotationToSet = QuaternionHelper.SmoothDamp(AttachedObject.GetRotation(), targetRot, ref _rotationSmoothVelocity, SmoothTime);
rotationToSet = SmartSmoothDamp(AttachedObject.GetRotation(), targetRot);
}
var hasMoved = CustomHasMoved(

View File

@ -86,7 +86,7 @@ namespace QSB.Syncs.Sectored.Transforms
if (UseInterpolation)
{
AttachedObject.localPosition = SmartSmoothDamp(AttachedObject.localPosition, targetPos);
AttachedObject.localRotation = QuaternionHelper.SmoothDamp(AttachedObject.localRotation, targetRot, ref _rotationSmoothVelocity, SmoothTime);
AttachedObject.localRotation = SmartSmoothDamp(AttachedObject.localRotation, targetRot);
}
else
{

View File

@ -104,8 +104,8 @@ namespace QSB.Syncs
protected virtual float DistanceLeeway { get; } = 5f;
private float _previousDistance;
protected const float SmoothTime = 0.1f;
protected Vector3 _positionSmoothVelocity;
protected Quaternion _rotationSmoothVelocity;
private Vector3 _positionSmoothVelocity;
private Quaternion _rotationSmoothVelocity;
protected bool _isInitialized;
protected abstract T SetAttachedObject();
@ -246,6 +246,11 @@ namespace QSB.Syncs
return Vector3.SmoothDamp(currentPosition, targetPosition, ref _positionSmoothVelocity, SmoothTime);
}
protected Quaternion SmartSmoothDamp(Quaternion currentRotation, Quaternion targetRotation)
{
return QuaternionHelper.SmoothDamp(currentRotation, targetRotation, ref _rotationSmoothVelocity, SmoothTime);
}
public void SetReferenceTransform(Transform referenceTransform)
{
if (ReferenceTransform == referenceTransform)

View File

@ -106,7 +106,7 @@ namespace QSB.Syncs.Unsectored.Rigidbodies
if (UseInterpolation)
{
positionToSet = SmartSmoothDamp(AttachedObject.GetPosition(), targetPos);
rotationToSet = QuaternionHelper.SmoothDamp(AttachedObject.GetRotation(), targetRot, ref _rotationSmoothVelocity, SmoothTime);
rotationToSet = SmartSmoothDamp(AttachedObject.GetRotation(), targetRot);
}
var hasMoved = CustomHasMoved(

View File

@ -60,7 +60,7 @@ namespace QSB.Syncs.Unsectored.Transforms
if (UseInterpolation)
{
AttachedObject.position = SmartSmoothDamp(AttachedObject.position, targetPos);
AttachedObject.rotation = QuaternionHelper.SmoothDamp(AttachedObject.rotation, targetRot, ref _rotationSmoothVelocity, SmoothTime);
AttachedObject.rotation = SmartSmoothDamp(AttachedObject.rotation, targetRot);
}
else
{