Everything works until 11:46 of the video.
Adding if target
to the _on_timer_timeout()
below doesn’t shoot projectiles…
@onready var turret_top: MeshInstance3D = $TurretBase/TurretTop
@export var projectile: PackedScene
var enemy_path: Path3D
var target: PathFollow3D
func _physics_process(delta: float) -> void:
var target = find_best_target()
if target:
look_at(target.global_position, Vector3.UP, true)
func _on_timer_timeout() -> void:
if target:
var shot = projectile.instantiate()
add_child(shot)
shot.global_position = turret_top.global_position
shot.direction = global_basis.z
func find_best_target() -> PathFollow3D:
var best_target = null
var best_progress = 0
for enemy in enemy_path.get_children():
if enemy is PathFollow3D:
if enemy.progress > best_progress:
best_progress = enemy.progress
best_target = enemy
return best_target