-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCameraFollowGameObject
More file actions
25 lines (22 loc) · 1003 Bytes
/
CameraFollowGameObject
File metadata and controls
25 lines (22 loc) · 1003 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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraFollow : MonoBehaviour {
public Transform m_player;
private Transform m_transform;
private Vector3 offset;
// Use this for initialization
void Start () {
m_transform = GetComponent<Transform>();
offset = m_player.position - m_transform.position;
}
// Update is called once per frame
void Update () {
//Debug.Log(offset + " " + offset + m_player.position +" " + m_player.TransformDirection(offset) + m_player.position);
Vector3 TargetPos = m_player.position - m_player.TransformDirection(offset);
m_transform.position = Vector3.Lerp(m_transform.position, TargetPos, Time.deltaTime * 5);
//Quaternion rotation = Quaternion.LookRotation(m_player.position - transform.position);
//m_transform.rotation = Quaternion.Slerp(m_transform.rotation, rotation, Time.deltaTime * 3f);
m_transform.LookAt(m_player.position);
}
}