quakeball/Assets/Scripts/Util/DesyncLerper.cs

24 lines
784 B
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace NeonTea.Quakeball.Util {
/// <summary>Used to offset visual parts of violently re-synced objects, so they can be smoothly lerped back to reality.</summary>
public class DesyncLerper : MonoBehaviour {
public float Speed = 1;
private Vector3 OffsetLeft;
public void Offset(Vector3 offset) {
transform.position += offset;
OffsetLeft += offset;
}
private void Update() {
Vector3 NewPosition = Vector3.Lerp(transform.position, transform.position - OffsetLeft, Speed * Time.deltaTime);
OffsetLeft += NewPosition - transform.position;
transform.position = NewPosition;
}
}
}