Fix heads desyncing off bodies

This commit is contained in:
Jens Pitkänen 2020-08-08 04:36:40 +03:00
parent 0bcc31093c
commit 7cbcc1de96
2 changed files with 18 additions and 6 deletions

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: ce4b9792bad15a54497d2a19cce83764
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -3,21 +3,22 @@ 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>
/// <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;
private Vector3 OffsetLeft;
private Vector3 OriginalLocalPosition;
public void Offset(Vector3 offset) {
transform.position += offset;
OffsetLeft += offset;
}
private void Awake() {
OriginalLocalPosition = transform.localPosition;
}
private void Update() {
Vector3 NewPosition = Vector3.Lerp(transform.position, transform.position - OffsetLeft, Speed * Time.deltaTime);
OffsetLeft += NewPosition - transform.position;
transform.position = NewPosition;
transform.localPosition = Vector3.Lerp(transform.localPosition, OriginalLocalPosition, Speed * Time.deltaTime);
}
}
}