diff --git a/Assets/Mirror/Components/PredictedRigidbody/PredictedRigidbody.cs b/Assets/Mirror/Components/PredictedRigidbody/PredictedRigidbody.cs index 97f8da9a6..f66ae19d5 100644 --- a/Assets/Mirror/Components/PredictedRigidbody/PredictedRigidbody.cs +++ b/Assets/Mirror/Components/PredictedRigidbody/PredictedRigidbody.cs @@ -6,53 +6,6 @@ namespace Mirror { - struct RigidbodyState : PredictedState - { - public double timestamp { get; private set; } - - // we want to store position delta (last + delta = current), and current. - // this way we can apply deltas on top of corrected positions to get the corrected final position. - public Vector3 positionDelta { get; set; } // delta to get from last to this position - public Vector3 position { get; set; } - - public Quaternion rotation; // TODO delta rotation? - - public Vector3 velocityDelta { get; set; } // delta to get from last to this velocity - public Vector3 velocity { get; set; } - - public RigidbodyState( - double timestamp, - Vector3 positionDelta, Vector3 position, - Quaternion rotation, - Vector3 velocityDelta, Vector3 velocity) - { - this.timestamp = timestamp; - this.positionDelta = positionDelta; - this.position = position; - this.rotation = rotation; - this.velocityDelta = velocityDelta; - this.velocity = velocity; - } - - // adjust the deltas after inserting a correction between this one and the previous one. - public void AdjustDeltas(float multiplier) - { - positionDelta = Vector3.Lerp(Vector3.zero, positionDelta, multiplier); - // TODO if we have have a rotation delta, then scale it here too - velocityDelta = Vector3.Lerp(Vector3.zero, velocityDelta, multiplier); - } - - public static RigidbodyState Interpolate(RigidbodyState a, RigidbodyState b, float t) - { - return new RigidbodyState - { - position = Vector3.Lerp(a.position, b.position, t), - rotation = Quaternion.Slerp(a.rotation, b.rotation, t), - velocity = Vector3.Lerp(a.velocity, b.velocity, t) - }; - } - } - public enum CorrectionMode { Set, // rigidbody.position/rotation = ... diff --git a/Assets/Mirror/Components/PredictedRigidbody/RigidbodyState.cs b/Assets/Mirror/Components/PredictedRigidbody/RigidbodyState.cs new file mode 100644 index 000000000..0a544f770 --- /dev/null +++ b/Assets/Mirror/Components/PredictedRigidbody/RigidbodyState.cs @@ -0,0 +1,52 @@ +// PredictedRigidbody stores a history of its rigidbody states. +using UnityEngine; + +namespace Mirror +{ + public struct RigidbodyState : PredictedState + { + public double timestamp { get; private set; } + + // we want to store position delta (last + delta = current), and current. + // this way we can apply deltas on top of corrected positions to get the corrected final position. + public Vector3 positionDelta { get; set; } // delta to get from last to this position + public Vector3 position { get; set; } + + public Quaternion rotation; // TODO delta rotation? + + public Vector3 velocityDelta { get; set; } // delta to get from last to this velocity + public Vector3 velocity { get; set; } + + public RigidbodyState( + double timestamp, + Vector3 positionDelta, Vector3 position, + Quaternion rotation, + Vector3 velocityDelta, Vector3 velocity) + { + this.timestamp = timestamp; + this.positionDelta = positionDelta; + this.position = position; + this.rotation = rotation; + this.velocityDelta = velocityDelta; + this.velocity = velocity; + } + + // adjust the deltas after inserting a correction between this one and the previous one. + public void AdjustDeltas(float multiplier) + { + positionDelta = Vector3.Lerp(Vector3.zero, positionDelta, multiplier); + // TODO if we have have a rotation delta, then scale it here too + velocityDelta = Vector3.Lerp(Vector3.zero, velocityDelta, multiplier); + } + + public static RigidbodyState Interpolate(RigidbodyState a, RigidbodyState b, float t) + { + return new RigidbodyState + { + position = Vector3.Lerp(a.position, b.position, t), + rotation = Quaternion.Slerp(a.rotation, b.rotation, t), + velocity = Vector3.Lerp(a.velocity, b.velocity, t) + }; + } + } +} diff --git a/Assets/Mirror/Components/PredictedRigidbody/RigidbodyState.cs.meta b/Assets/Mirror/Components/PredictedRigidbody/RigidbodyState.cs.meta new file mode 100644 index 000000000..93affc5e7 --- /dev/null +++ b/Assets/Mirror/Components/PredictedRigidbody/RigidbodyState.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: ed0e1c0c874c4c9db6be2d5885bb7bee +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {fileID: 2800000, guid: 7453abfe9e8b2c04a8a47eb536fe21eb, type: 3} + userData: + assetBundleName: + assetBundleVariant: