blob: 3905c84c34a34cf0dfc07920afed59a321664306 (
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
|
using UnityEngine;
public class FPSCarCam : MonoBehaviour
{
public Rigidbody rig;
public float movementAmount = 1f;
public float returnAmount = 1f;
public float friction = 0.9f;
private Vector3 cameraVelocity;
private Vector3 lastRigVelocity;
private Vector3 startPos;
private WobbleShake shake;
private void Start()
{
startPos = base.transform.localPosition;
shake = base.transform.root.GetComponentInChildren<WobbleShake>();
}
private void Update()
{
Vector3 vector = rig.velocity - lastRigVelocity;
cameraVelocity -= vector;
cameraVelocity -= cameraVelocity * Time.deltaTime * friction;
Vector3 vector2 = base.transform.parent.TransformPoint(startPos) - base.transform.position;
cameraVelocity += vector2.normalized * Mathf.Pow(vector2.magnitude, 2f) * Time.deltaTime * returnAmount;
base.transform.position += cameraVelocity * Time.deltaTime * movementAmount;
base.transform.rotation = Quaternion.Lerp(base.transform.rotation, rig.rotation, 10f * Time.deltaTime);
lastRigVelocity = rig.velocity;
}
private void FixedUpdate()
{
}
}
|