-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlayerCamera
66 lines (51 loc) · 1.68 KB
/
PlayerCamera
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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraMovement : MonoBehaviour
{
public GameObject cameraEyes;
public GameObject cameraObject;
public float mouseSpeed = 100f;
public GameObject playerBody;
public float xRotation = 0f;
public float yRotation = 0f;
private float tiltRotation = 0f;
public float tiltLeft = 15f;
public float tiltRight = -15;
// Start is called before the first frame update
void Start()
{
xRotation = cameraEyes.transform.rotation.eulerAngles.x;
yRotation = cameraEyes.transform.rotation.eulerAngles.y;
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = false;
}
// Update is called once per frame
void Update()
{
LookAround();
}
private void LookAround()
{
float mouseX = Input.GetAxis("Mouse X") * mouseSpeed * Time.deltaTime;
float mouseY = Input.GetAxis("Mouse Y") * mouseSpeed * Time.deltaTime;
//the rotation of the body
xRotation -= mouseY;
xRotation = Mathf.Clamp(xRotation, -90f, 90f);
yRotation += mouseX;
playerBody.transform.rotation = Quaternion.Euler(0f, yRotation, 0f);
cameraEyes.transform.rotation = Quaternion.Euler(xRotation, yRotation, Mathf.LerpAngle(cameraEyes.transform.eulerAngles.z, tiltRotation, 5f * Time.deltaTime));
}
public void leftWallRunCamera()
{
tiltRotation = tiltRight;
}
public void righttWallRunCamera()
{
tiltRotation = tiltLeft;
}
public void resetCameraAfterWallRun()
{
tiltRotation = 0f;
}
}