extends KinematicBody
-const SPEED_FORWARD = 2
+const SPEED_FORWARD = 20
+const SPEED_MAX = 20
const SPEED_TURN = 120
const SPEED_AIM = PI / 2
-const FRICTION = 0.95
var velocity = Vector3()
+var scene_bullet = preload("res://player/bullet.tscn")
# Called when the node enters the scene tree for the first time.
func _ready():
elif Input.is_action_pressed("player_aim_right"):
rotate(Vector3.UP, -SPEED_AIM * delta)
+ # offense
+ if Input.is_action_pressed("player_fire"):
+ print("firing!")
+ fire_bullet()
+
+func fire_bullet():
+ var bullet = scene_bullet.instance()
+ $"..".add_child(bullet)
+ bullet.translation = translation - transform.basis.x * 2
+ bullet.rotation = rotation
+ bullet.direction = -transform.basis.z
func _process(delta):
# get velocity changes player asks for
# move foward according to the camera's POV
var vec_forward = transform.basis.z
velocity += SPEED_FORWARD * -vec_forward * delta
+
+ # air friction
+ var friction = SPEED_MAX / velocity.length()
+ velocity *= friction
func _physics_process(_delta):
velocity = move_and_slide(velocity, Vector3.UP)