-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCameraFollow.cs
More file actions
27 lines (21 loc) · 855 Bytes
/
Copy pathCameraFollow.cs
File metadata and controls
27 lines (21 loc) · 855 Bytes
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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraFollow : MonoBehaviour
{
public Transform target;
public float smoothSpeed;
public float minimumHeight;
public float yDistance;
public float zDistance;
private Vector3 positionVelocity;
private void FixedUpdate()
{
Vector3 chosenPosition = target.position + (target.forward * zDistance);
chosenPosition.y = Mathf.Max(chosenPosition.y + yDistance, minimumHeight);
Vector3 smoothedPositin = Vector3.SmoothDamp(transform.position, chosenPosition, ref positionVelocity, smoothSpeed * Time.deltaTime);
transform.position = smoothedPositin;
Vector3 moveAndRotate = target.position + (target.forward * 5f);
transform.LookAt(moveAndRotate);
}
}