3 const SPEED_FORWARD = 20
6 const SPEED_AIM = PI / 2
8 var bullet_alterating = 0
9 var velocity = Vector3()
10 var scene_bullet = preload("res://player/bullet.tscn")
12 # Called when the node enters the scene tree for the first time.
14 pass # Replace with function body.
16 func get_player_input(delta):
17 var vec_lateral = transform.basis.x
18 var vec_vertical = transform.basis.y
21 if Input.is_action_pressed("player_left"):
22 velocity += SPEED_TURN * -vec_lateral * delta
23 elif Input.is_action_pressed("player_right"):
24 velocity += SPEED_TURN * vec_lateral * delta
26 if Input.is_action_pressed("player_up"):
27 velocity += SPEED_TURN * vec_vertical * delta
28 elif Input.is_action_pressed("player_down"):
29 velocity += SPEED_TURN * -vec_vertical * delta
31 if Input.is_action_pressed("player_aim_up"):
32 rotate_object_local(Vector3.RIGHT, SPEED_AIM * delta)
33 elif Input.is_action_pressed("player_aim_down"):
34 rotate_object_local(Vector3.RIGHT, -SPEED_AIM * delta)
36 if Input.is_action_pressed("player_aim_left"):
37 rotate(Vector3.UP, SPEED_AIM * delta)
38 elif Input.is_action_pressed("player_aim_right"):
39 rotate(Vector3.UP, -SPEED_AIM * delta)
42 if Input.is_action_pressed("player_fire"):
43 if $bullet_timer.time_left == 0:
47 var bullet = scene_bullet.instance()
48 $"..".add_child(bullet)
50 bullet_alterating = (bullet_alterating + 1) % 2
51 bullet.translation = translation - transform.basis.x * (4 * bullet_alterating - 2)
52 bullet.rotation = rotation
53 bullet.direction = -transform.basis.z
58 # get velocity changes player asks for
59 get_player_input(delta)
61 # move foward according to the camera's POV
62 var vec_forward = transform.basis.z
63 velocity += SPEED_FORWARD * -vec_forward * delta
66 var friction = SPEED_MAX / velocity.length()
69 func _physics_process(_delta):
70 velocity = move_and_slide(velocity, Vector3.UP)