public static Snapshot3D Interpolate(Snapshot3D from, Snapshot3D to, double t) => new Snapshot3D( // TODO // interpolated snapshot is applied directly. don't need timestamps. 0, 0, // TODO // lerp unclamped in case we ever need to extrapolate. Vector2.LerpUnclamped(from.position, to.position, (float)t));
void Update() { // snapshot interpolation if (interpolate) { // compute snapshot interpolation & apply if any was spit out // TODO we don't have Time.deltaTime double yet. float is fine. if (Mirror.SnapshotInterpolation.Compute( Time.time, Time.deltaTime, ref serverInterpolationTime, bufferTime, snapshots, catchupThreshold, catchupMultiplier, Interpolate, out Snapshot3D computed, out lastCatchup)) { transform.position = computed.position; } } // apply raw else { if (snapshots.Count > 0) { Snapshot3D snap = snapshots.Values[0]; transform.position = snap.position; snapshots.RemoveAt(0); } } // color material while catching up render.sharedMaterial.color = lastCatchup > 0 ? catchupColor : defaultColor; }
public void OnMessage(Snapshot3D snap) { snap.localTimestamp = Time.time; Mirror.SnapshotInterpolation.InsertIfNewEnough(snap, snapshots); }