sunoku/scenes/enemies/shooter/gun.gd

21 lines
685 B
GDScript

extends RayCast2D
@onready var carrier = get_parent()
@export var attack_cooldown : float = 1
@export var bullet_scene : PackedScene
var attack_timer = 0
func _process(delta: float) -> void:
attack_timer -= delta
target_position = carrier.player.global_position-global_position
if not is_colliding() and attack_timer < 0:
var new_bullet = bullet_scene.instantiate()
new_bullet.hostile = true
new_bullet.direction = global_position.direction_to(carrier.player.global_position)
new_bullet.global_position = global_position
new_bullet.damage = carrier.player.incoming_damage
new_bullet.speed = 5
get_tree().root.add_child(new_bullet)
attack_timer = attack_cooldown