]> Untitled Git - star-foxy.git/blob - player/player.gd
Made plane feel better
[star-foxy.git] / player / player.gd
1 extends KinematicBody
2
3 const SPEED_FORWARD = 2
4 const SPEED_TURN = 120
5 const SPEED_AIM = PI / 2
6 const FRICTION = 0.95
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_object_local(Vector3.RIGHT, SPEED_AIM * delta)
31         elif Input.is_action_pressed("player_aim_down"):
32                 rotate_object_local(Vector3.RIGHT, -SPEED_AIM * delta)  
33                 
34         if Input.is_action_pressed("player_aim_left"):
35                 rotate(Vector3.UP, SPEED_AIM * delta)
36         elif Input.is_action_pressed("player_aim_right"):
37                 rotate(Vector3.UP, -SPEED_AIM * delta)  
38                 
39         
40 func _process(delta):
41         # get velocity changes player asks for
42         get_player_input(delta)
43         
44         # move foward according to the camera's POV
45         var vec_forward = transform.basis.z
46         velocity += SPEED_FORWARD * -vec_forward * delta
47
48 func _physics_process(_delta):
49         velocity = move_and_slide(velocity, Vector3.UP)