]> Untitled Git - star-foxy.git/blob - player/player.gd
53bd3ed500259114a93cd216d6d67f71cb75e0cb
[star-foxy.git] / player / player.gd
1 extends KinematicBody
2
3 const SPEED_FORWARD = 5
4 const SPEED_TURN = 60
5 const SPEED_AIM = PI / 4
6 const FRICTION = 0.99
7
8 var velocity = Vector3()
9
10 # Called when the node enters the scene tree for the first time.
11 func _ready():
12         pass # Replace with function body.
13
14 func get_player_input(delta):
15         var vec_lateral = transform.basis.x
16         var vec_vertical = transform.basis.y
17         
18         
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
23                 
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
28         
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)    
33                 
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)    
38                 
39         
40 func _process(delta):
41         # get velocity changes player asks for
42         get_player_input(delta)
43         velocity.x *= FRICTION
44         velocity.y *= FRICTION
45         
46         # move foward according to the camera's POV
47         var vec_forward = transform.basis.z
48         velocity += SPEED_FORWARD * -vec_forward * delta
49
50 func _physics_process(delta):
51         velocity = move_and_slide(velocity, Vector3.UP)