blob: c22d174112eae3aabf7d9c0c369d719642eb4101 (
plain)
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
|
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController : MonoBehaviour
{
public float m_MoveSpeed = 1f;
public float m_CameraRotation;
public float m_LookSensitive;
public Transform m_Eye;
public float m_LookSmooth;
public float m_BodyRotation;
// Start is called before the first frame update
void Start()
{
Cursor.lockState = CursorLockMode.Locked;
}
void LookAround()
{
float mouseX = Input.GetAxis("Mouse X");
float mouseY = Input.GetAxis("Mouse Y");
//mouseX = -0.1f; // test jittery
m_CameraRotation -= mouseY * Time.deltaTime * m_LookSensitive;
m_CameraRotation = Mathf.Clamp(m_CameraRotation, -90, 90);
Quaternion rot = Quaternion.Euler(m_CameraRotation, 0, 0);
m_Eye.localRotation = Quaternion.Slerp(m_Eye.localRotation, rot, m_LookSmooth);
m_BodyRotation += mouseX * Time.deltaTime * m_LookSensitive;
rot = Quaternion.Euler(0, m_BodyRotation, 0);
transform.localRotation = Quaternion.Slerp(transform.localRotation, rot, m_LookSmooth);
}
// Update is called once per frame
void Update()
{
float moveX = Input.GetAxisRaw("Horizontal");
float moveZ = Input.GetAxisRaw("Vertical");
Vector3 dir = transform.right * moveX + transform.forward * moveZ;
if (dir.magnitude > 0)
{
dir = dir.normalized;
Vector3 velocity = dir * m_MoveSpeed;
transform.position += velocity * Time.deltaTime;
}
LookAround();
}
}
|