Snapshot3D.cs 903 B

1234567891011121314151617181920212223242526
  1. // a simple snapshot with timestamp & interpolation
  2. using UnityEngine;
  3. namespace Mirror.Examples.SnapshotInterpolationDemo
  4. {
  5. public struct Snapshot3D : Snapshot
  6. {
  7. public double remoteTime { get; set; }
  8. public double localTime { get; set; }
  9. public Vector3 position;
  10. public Snapshot3D(double remoteTime, double localTime, Vector3 position)
  11. {
  12. this.remoteTime = remoteTime;
  13. this.localTime = localTime;
  14. this.position = position;
  15. }
  16. public static Snapshot3D Interpolate(Snapshot3D from, Snapshot3D to, double t) =>
  17. new Snapshot3D(
  18. // interpolated snapshot is applied directly. don't need timestamps.
  19. 0, 0,
  20. // lerp unclamped in case we ever need to extrapolate.
  21. Vector3.LerpUnclamped(from.position, to.position, (float)t));
  22. }
  23. }