]> Untitled Git - star-foxy.git/blob - player/player.gd
Initial flight mechanics
[star-foxy.git] / player / player.gd
1 extends KinematicBody
2
3 const SPEED = 20
4
5 var velocity = Vector3()
6
7 # Called when the node enters the scene tree for the first time.
8 func _ready():
9         pass # Replace with function body.
10
11 func get_player_input(delta):
12         var cam_vec_lateral = $Camera.transform.basis.x
13         var cam_vec_vertical = $Camera.transform.basis.y
14         
15         
16         if Input.is_action_pressed("player_left"):
17                 velocity += SPEED * cam_vec_lateral * delta
18         elif Input.is_action_pressed("player_right"):
19                 velocity += SPEED * -cam_vec_lateral * delta
20                 
21         if Input.is_action_pressed("player_up"):
22                 velocity += SPEED * cam_vec_vertical * delta
23         elif Input.is_action_pressed("player_down"):
24                 velocity += SPEED * -cam_vec_vertical * delta
25                 
26                 
27 func _process(delta):
28         # move foward according to the camera's POV
29         var cam_vec_forward = $Camera.transform.basis.z
30         velocity += SPEED * -cam_vec_forward * delta
31         
32         # get velocity changes player asks for
33         get_player_input(delta)
34         
35 func _physics_process(_delta):
36         velocity = move_and_slide(velocity, Vector3.UP)