What changes can I make in this script to make canon shoot in every direction at specific times ?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Scavex

I want the cannon to shoot at all directions after every second. This current script is of a Canon that shoots my player when he is in it’s range :

extends Sprite
var player=null

var rot_sped=0.3
var fire_rate=0.3
var fire_time=0.5
var rang=300


var canonbullet=preload("res://CanonBullet.tscn")

func _physics_process(delta):
	if player==null:
		return
	var dir_to_player=player.global_position-global_position
	rotation=dir_to_player.angle()
	fire_time+=delta
	if fire_time>fire_rate:
		fire_time=0
		fire()


func fire():
	if global_position.distance_to(player.global_position)>rang:
		return
	var canonbullet_inst=canonbullet.instance()
	get_tree().get_root().add_child(canonbullet_inst)
	canonbullet_inst.global_position=global_position
	var dir_to_player=(player.global_position-global_position).normalized()
	canonbullet_inst.move_dir=dir_to_player

func set_player(p):
	player=p


func _on_Area2D_body_entered(body: Node) -> void:
	if "Player" in body.name:
		get_tree().reload_current_scene()
:bust_in_silhouette: Reply From: deaton64

Hi,

Add a timer node.
Make it one shot with Wait Time of 1 second.
Add a signal for timeout()

In the timeout code, add something like:

func _on_Timer_timeout() -> void:
    move the fire code from _physics_process to here
    $Timer.start()