extends Node3D
class_name Bullet

const MAX_LIFETIME = 3.

var damage : float = 10.
var speed : float = 150.
var lifetime : float = 0.

@onready var raycast : RayCast3D = %RayCast3D

func _process(delta):
    lifetime += delta
    position += transform.basis * Vector3(0,0,-speed) * delta

    if raycast.is_colliding():
        if raycast.get_collider() is Alien:
            raycast.get_collider().hit(damage)
            queue_free()
        if raycast.get_collider() is StaticBody3D:
            queue_free()

    if lifetime > MAX_LIFETIME:
        queue_free()