-
Notifications
You must be signed in to change notification settings - Fork 0
/
CameraSystem.cs
98 lines (71 loc) · 2.41 KB
/
CameraSystem.cs
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraSystem : MonoBehaviour
{
public static CameraSystem instance;
private void Awake()
{
instance = this;
moveTarget = transform.position;
}
[Header("Camera Variables")]
public float moveSpeed, manualMoveSpeed;
float targetRot; //Rotation
public float rotateSpeed;
int currentAngle;
[Header("Input Keys")]
public KeyCode snapBackToPlayer;
public KeyCode rotateLeft;
public KeyCode rotateRight;
Vector3 moveTarget; //Target that Camera should follow
Vector2 moveInput; //For Manual Camera Movement
private void Start()
{
}
private void Update()
{
if (moveTarget != transform.position)
{
transform.position = Vector3.MoveTowards(transform.position, moveTarget, moveSpeed * Time.deltaTime);
}
if ((LevelManager.Instance?.PlayerCanControl ?? true) && (!PauseMenu.Instance?.IsPaused ?? false))
{
moveInput.x = Input.GetAxis("Horizontal");
moveInput.y = Input.GetAxis("Vertical");
moveInput.Normalize();
if (moveInput != Vector2.zero)
{
transform.position += ((transform.forward * (moveInput.y * manualMoveSpeed)) +
(transform.right * (moveInput.x * manualMoveSpeed))) * Time.deltaTime;
moveTarget = transform.position;
}
if (Input.GetKeyDown(snapBackToPlayer)) //Snapping back to player
{
SetMoveTarget(GameManager.instance.ActivePlayer.transform.position);
}
if (Input.GetKeyDown(rotateLeft)) //Rotate Right
{
currentAngle++;
if (currentAngle >= 4)
{
currentAngle = 0;
}
}
if (Input.GetKeyDown(rotateRight)) //Rotate Left
{
currentAngle--;
if (currentAngle < 0)
{
currentAngle = 3;
}
}
}
targetRot = (90f * currentAngle) + 45f;
transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.Euler(0f, targetRot, 0f), rotateSpeed * Time.deltaTime);
}
public void SetMoveTarget(Vector3 newTarget)
{
moveTarget = newTarget;
}
}