summaryrefslogtreecommitdiffstats
path: root/Player.gd
blob: 335a73c4a05ed7dab4fa7ef6c77553f8d467c9a3 (plain) (blame)
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
extends KinematicBody

export var speed = 20
export var ang_speed = PI
export var mouse_sens = 0.2
export var pitch_min = -0.8
export var pitch_max = 0.8

func _physics_process(delta):
	var local_up = transform.basis.y.normalized()
	var local_right = transform.basis.x.normalized()
	var local_forward = -transform.basis.z.normalized()

	var stick = Input.get_vector("move_left", "move_right", "move_back", "move_forward")
	var vert = Input.get_axis("move_down", "move_up")

	var movement = Vector3.ZERO
	movement += local_right * stick.x * speed
	movement += local_forward * stick.y * speed
	movement += local_up * vert * speed
	movement = move_and_slide(movement, Vector3.UP)

	stick = Input.get_vector("look_right", "look_left", "look_down", "look_up")
	var mouse_movement = MouseInput.get_mouse_movement()
	if stick.length() == 0.0:
		stick.x = -mouse_movement.x * mouse_sens
		stick.y = -mouse_movement.y * mouse_sens
	rotation.x += stick.y * ang_speed * delta
	rotation.x = clamp(rotation.x, pitch_min, pitch_max)
	rotation.y += stick.x * ang_speed * delta
	rotation.y = wrapf(rotation.y, 0, TAU)