-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMovementScript.cs
More file actions
37 lines (28 loc) · 959 Bytes
/
Copy pathMovementScript.cs
File metadata and controls
37 lines (28 loc) · 959 Bytes
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
using UnityEngine;
public class MovementScript : MonoBehaviour
{
public float moveSpeed = 10f;
public float mouseSensitivity = 2f;
float pitch = 0f;
float yaw = 0f;
void Start()
{
Cursor.lockState = CursorLockMode.Locked;
}
void Update()
{
float moveX = Input.GetAxis("Horizontal");
float moveZ = Input.GetAxis("Vertical");
float moveY = 0f;
if (Input.GetKey(KeyCode.Space)) moveY += 1f;
if (Input.GetKey(KeyCode.Tab)) moveY -= 1f;
Vector3 move = new Vector3(moveX, moveY, moveZ);
transform.Translate(move * moveSpeed * Time.deltaTime, Space.Self);
float mouseX = Input.GetAxis("Mouse X") * mouseSensitivity;
float mouseY = Input.GetAxis("Mouse Y") * mouseSensitivity;
yaw += mouseX;
pitch -= mouseY;
pitch = Mathf.Clamp(pitch, -90f, 90f);
transform.rotation = Quaternion.Euler(pitch, yaw, 0f);
}
}