3 const SPEED_FORWARD = 5
5 const SPEED_AIM = PI / 4
8 var velocity = Vector3()
10 # Called when the node enters the scene tree for the first time.
12 pass # Replace with function body.
14 func get_player_input(delta):
15 var vec_lateral = transform.basis.x
16 var vec_vertical = transform.basis.y
19 if Input.is_action_pressed("player_left"):
20 velocity += SPEED_TURN * -vec_lateral * delta
21 elif Input.is_action_pressed("player_right"):
22 velocity += SPEED_TURN * vec_lateral * delta
24 if Input.is_action_pressed("player_up"):
25 velocity += SPEED_TURN * vec_vertical * delta
26 elif Input.is_action_pressed("player_down"):
27 velocity += SPEED_TURN * -vec_vertical * delta
29 if Input.is_action_pressed("player_aim_up"):
30 rotate_x(SPEED_AIM * delta)
31 elif Input.is_action_pressed("player_aim_down"):
32 rotate_x(-SPEED_AIM * delta)
34 if Input.is_action_pressed("player_aim_left"):
35 rotate_y(SPEED_AIM * delta)
36 elif Input.is_action_pressed("player_aim_right"):
37 rotate_y(-SPEED_AIM * delta)
41 # get velocity changes player asks for
42 get_player_input(delta)
43 velocity.x *= FRICTION
44 velocity.y *= FRICTION
46 # move foward according to the camera's POV
47 var vec_forward = transform.basis.z
48 velocity += SPEED_FORWARD * -vec_forward * delta
50 func _physics_process(delta):
51 velocity = move_and_slide(velocity, Vector3.UP)