-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMouseLook.cs
More file actions
98 lines (73 loc) · 2.32 KB
/
MouseLook.cs
File metadata and controls
98 lines (73 loc) · 2.32 KB
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 MouseLook : MonoBehaviour
{
[SerializeField]
private Transform playerRoot, lookRoot;
[SerializeField]
private bool invert;
[SerializeField]
private bool can_Unlock = true;
[SerializeField]
private float sensivity = 5f;
[SerializeField]
private int smooth_Steps = 10;
[SerializeField]
private float smooth_Weight = 0.4f;
[SerializeField]
private float roll_Angle = 10f;
[SerializeField]
private float roll_Speed = 3f;
[SerializeField]
private Vector2 default_Look_Limits = new Vector2(-70f, 80f);
private Vector2 look_Angles;
private Vector2 current_Mouse_Look;
private Vector2 smooth_Move;
private float current_Roll_Angle;
private int last_Look_Frame;
// Start is called before the first frame update
void Start()
{
Cursor.lockState = CursorLockMode.Locked;
}
// Update is called once per frame
void Update()
{
LockAndUnlockCursor();
if(Cursor.lockState == CursorLockMode.Locked)
{
LookAround();
}
}
// lock and unlock
void LockAndUnlockCursor()
{
if (Input.GetKeyDown(KeyCode.Escape))
{
if (Cursor.lockState == CursorLockMode.Locked)
{
Cursor.lockState = CursorLockMode.None;
}
else
{
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = false;
}
}
}
// look around
void LookAround()
{
current_Mouse_Look = new Vector2(
Input.GetAxis(MouseAxis.MOUSE_Y), Input.GetAxis(MouseAxis.MOUSE_X));
look_Angles.x += current_Mouse_Look.x * sensivity * (invert ? 1f : -1f);
look_Angles.y += current_Mouse_Look.y * sensivity;
look_Angles.x = Mathf.Clamp(look_Angles.x, default_Look_Limits.x, default_Look_Limits.y);
//current_Roll_Angle =
//Mathf.Lerp(current_Roll_Angle, Input.GetAxisRaw(MouseAxis.MOUSE_X)
//* roll_Angle, Time.deltaTime * roll_Speed);
lookRoot.localRotation = Quaternion.Euler(look_Angles.x, 0f, 0f);
playerRoot.localRotation = Quaternion.Euler(0f, look_Angles.y, 0f);
}
}