blob: 1d5a5b417490f6fc7bad5a0153c13011147dc693 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
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);
}
}
|