extends Node3D

signal destination_reached


var is_live: bool = false
var is_loaded: bool = false
var is_target_reached: bool = true

var target_position: Vector3

func _ready() -> void:
	GameManager.add_bullet(self)
	target_position = Vector3.ZERO
	destination_reached.connect(on_target_reached)

func _process(delta: float) -> void:
	if is_target_reached == false:
		self.global_position = lerp(global_position, target_position, delta / 0.1)
		
	if global_position.distance_to(target_position) < 0.1/1000 and is_target_reached == false:
		
		destination_reached.emit()

func moveTo(target_pos: Vector3):
	target_position = target_pos
	is_target_reached = false

func on_target_reached():
	print("Target Reached")
	is_target_reached = true


func _on_static_body_3d_input_event(camera: Node, event: InputEvent, event_position: Vector3, normal: Vector3, shape_idx: int) -> void:
	if event.is_action_released("left_mouse_click"):
		GameManager.bullet_selected.emit(self)
