summaryrefslogtreecommitdiff
path: root/Other/CADEMO/Assets/Scripts/PlayerController.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Other/CADEMO/Assets/Scripts/PlayerController.cs')
-rw-r--r--Other/CADEMO/Assets/Scripts/PlayerController.cs57
1 files changed, 57 insertions, 0 deletions
diff --git a/Other/CADEMO/Assets/Scripts/PlayerController.cs b/Other/CADEMO/Assets/Scripts/PlayerController.cs
new file mode 100644
index 0000000..c22d174
--- /dev/null
+++ b/Other/CADEMO/Assets/Scripts/PlayerController.cs
@@ -0,0 +1,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();
+
+ }
+}