diff options
Diffstat (limited to 'ForceLerp.cs')
-rw-r--r-- | ForceLerp.cs | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/ForceLerp.cs b/ForceLerp.cs new file mode 100644 index 0000000..1d5a5b4 --- /dev/null +++ b/ForceLerp.cs @@ -0,0 +1,59 @@ +using UnityEngine; + +public class ForceLerp : MonoBehaviour +{ + public Rigidbody rig; + + public float predictionAmount; + + public Transform target; + + public float movementMultiplier = 1f; + + public float friction = 0.97f; + + private Vector3 velocity; + + public float inputVelocityAmount; + + public float inputFriction; + + private GenericInputHandler input; + + private float inputVelocity; + + private CollisionChecker[] checkers; + + private void Start() + { + input = GetComponentInParent<GenericInputHandler>(); + checkers = base.transform.root.GetComponentsInChildren<CollisionChecker>(); + } + + private void FixedUpdate() + { + } + + private void LateUpdate() + { + float num = Mathf.Clamp(Time.smoothDeltaTime, 0f, 0.1f); + float num2 = 1f; + if (checkers.Length > 0) + { + num2 = 0f; + for (int i = 0; i < checkers.Length; i++) + { + if (checkers[i].sinceGrounded < 0.2f) + { + num2 += 1f / (float)checkers.Length; + } + } + } + inputVelocity += rig.angularVelocity.y * 0.5f * num2 * num - num * inputVelocity * inputFriction; + Vector3 vector = target.position - base.transform.position + rig.transform.right * inputVelocity * inputVelocityAmount + rig.velocity * predictionAmount; + Vector3 vector2 = velocity * friction; + velocity += (vector - vector2) * num; + base.transform.position += velocity * movementMultiplier * num; + base.transform.rotation = Quaternion.Lerp(base.transform.rotation, Quaternion.LookRotation(target.forward), num * 4f); + } +} |