aboutsummaryrefslogtreecommitdiffstats
path: root/Assets/Scripts/FollowCamera.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Assets/Scripts/FollowCamera.cs')
-rw-r--r--Assets/Scripts/FollowCamera.cs32
1 files changed, 32 insertions, 0 deletions
diff --git a/Assets/Scripts/FollowCamera.cs b/Assets/Scripts/FollowCamera.cs
new file mode 100644
index 0000000..5b58766
--- /dev/null
+++ b/Assets/Scripts/FollowCamera.cs
@@ -0,0 +1,32 @@
+using System.Collections;
+using UnityEngine;
+
+public class FollowCamera : MonoBehaviour
+{
+ public float speed = 15f;
+ public float minDistance;
+ public GameObject target;
+ public Vector3 offset;
+
+ private Vector3 targetPos;
+
+ // Use this for initialization
+ void Start()
+ {
+ targetPos = transform.position;
+ }
+
+ // Update is called once per frame
+ void Update()
+ {
+ if (target)
+ {
+ Vector3 posNoZ = transform.position + offset;
+ Vector3 targetDirection = (target.transform.position - posNoZ);
+ float interpVelocity = targetDirection.magnitude * speed;
+ targetPos = (transform.position) + (targetDirection.normalized * interpVelocity * Time.deltaTime);
+
+
+ }
+ }
+} \ No newline at end of file