extends CharacterBody3D
class_name Bullet

var target : CharacterBody3D
var speed : int = 20
var bullet_damage : int = 1

func _physics_process(delta: float) -> void:
	if is_instance_valid(target):
		velocity = global_position.direction_to(target.global_position) * speed
		look_at(target.global_position)
		
		move_and_slide()
	else:
		queue_free()

func _on_impact_body_entered(body: Node3D) -> void:
	if body is Enemy:
		var enemy : Enemy = body
		enemy.take_damage(bullet_damage)
		queue_free()
