extends Node2D const TurretBullet = preload("res://objects/environment/turret/turret_bullet.tscn") export var delay = 0.0 export var fire_rate = 10.0 export var bullet_spread = 15.0 export var bullet_speed = 200.0 # do not set manually, controlled by AnimationPlayer export var shooting = false onready var barrel_start = $BarrelStart onready var barrel_end = $BarrelStart/BarrelEnd var bullet_cooldown = 1.0 func _ready(): bullet_spread = deg2rad(bullet_spread) $AnimationTree.active = true var timer = get_tree().create_timer(delay, false) timer.connect("timeout", $AnimationTree, "set", [ "parameters/conditions/shooting", true ]) func _physics_process(delta): if shooting: bullet_cooldown -= delta * fire_rate if bullet_cooldown <= 0.0: bullet_cooldown += 1.0 var bullet = TurretBullet.instance() bullet.global_position = barrel_end.global_position bullet.direction = (barrel_end.global_position - barrel_start.global_position).normalized() bullet.direction = bullet.direction.rotated(rand_range(-bullet_spread, bullet_spread)) bullet.speed = bullet_speed get_parent().call_deferred("add_child", bullet) Game.play_sound(Game.a_arrow, Game.ac_climb)