aboutsummaryrefslogtreecommitdiffstats
path: root/Assets/Scripts/FollowCamera.cs
blob: 5b58766605fa35165f6f051c9a74e9c95ef2ecfb (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
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);
            

        }
    }
}