2025-03-26 18:55:43 +01:00
|
|
|
extends CharacterBody3D
|
|
|
|
|
class_name Bullet
|
|
|
|
|
|
|
|
|
|
var target : CharacterBody3D
|
2025-04-02 18:02:13 +02:00
|
|
|
@export var speed : int = 20
|
2025-03-26 18:55:43 +01:00
|
|
|
var bullet_damage : int = 1
|
2025-06-18 12:19:43 +02:00
|
|
|
var start_position
|
|
|
|
|
|
|
|
|
|
func _ready() -> void:
|
|
|
|
|
global_position = start_position
|
|
|
|
|
|
2025-03-26 18:55:43 +01:00
|
|
|
|
|
|
|
|
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:
|
2025-06-18 12:19:43 +02:00
|
|
|
if body == target:
|
2025-03-26 18:55:43 +01:00
|
|
|
var enemy : Enemy = body
|
|
|
|
|
enemy.take_damage(bullet_damage)
|
|
|
|
|
queue_free()
|