quakeball/Assets/Scripts/Util/DesyncLerper.cs

25 lines
818 B
C#
Raw Permalink Normal View History

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace NeonTea.Quakeball.Util {
2020-08-08 03:36:40 +02:00
/// <summary>Used to offset visual parts of violently re-synced objects, so they can be smoothly lerped back to reality. This depends on the original localPosition staying the same.</summary>
public class DesyncLerper : MonoBehaviour {
public float Speed = 1;
2020-08-08 03:36:40 +02:00
private Vector3 OriginalLocalPosition;
public void Offset(Vector3 offset) {
transform.position += offset;
2020-08-08 03:36:40 +02:00
}
private void Awake() {
OriginalLocalPosition = transform.localPosition;
}
private void Update() {
2020-08-08 03:36:40 +02:00
transform.localPosition = Vector3.Lerp(transform.localPosition, OriginalLocalPosition, Speed * Time.deltaTime);
}
}
}