godot-tank-test/assets/scripts/weapons/autocannon.gd

29 lines
760 B
GDScript3
Raw Normal View History

extends Node3D
@export var _shots_per_minute = 100
var shotscene = preload("res://assets/scenes/round_autocannon.tscn")
var _is_firing = false
# Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
pass
func on_fire():
if _is_firing:
return
_is_firing = true
var shot = shotscene.instantiate()
shot.init_round($muzzle, $aimpoint.global_position - $muzzle.global_position)
get_tree().root.add_child(shot)
$AudioStreamPlayer3D.play()
$GPUParticles3D.emitting = true
$recoil_anim.play("recoil")
await get_tree().create_timer(60.0 / float(_shots_per_minute)).timeout
_is_firing = false