-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCarCameraScript.cs
More file actions
38 lines (32 loc) · 1.07 KB
/
Copy pathCarCameraScript.cs
File metadata and controls
38 lines (32 loc) · 1.07 KB
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
using UnityEngine;
using System.Collections;
public class CarCameraScript : MonoBehaviour {
public Transform car;
public float distance = 2.0f;
public float height = 0.5f;
public float rotationDamping = 3.0f;
public float heightDamping = 2.0f;
public float zoomRatio = 0.5f;
private Vector3 rotationVector;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
void LateUpdate () {
float wantedAngle = car.eulerAngles.y;
float wantedHeight = car.position.y + height;
float myAngle = transform.eulerAngles.y;
float myHeight = transform.position.y;
myAngle = Mathf.LerpAngle(myAngle,wantedAngle,rotationDamping*Time.deltaTime);
myHeight = Mathf.Lerp (myHeight,wantedHeight,heightDamping*Time.deltaTime);
Quaternion currentRotation = Quaternion.Euler(0,myAngle,0);
transform.position = car.position;
transform.position -= currentRotation*Vector3.forward*distance;
Vector3 newPosition = transform.position;
newPosition.y = myHeight;
transform.position = newPosition;
transform.LookAt(car);
}
}