2025-01-28 18:32:38 +00:00
|
|
|
class_name WeaponController extends Node3D
|
|
|
|
@export_category("WeaponController")
|
2025-01-28 09:51:45 +00:00
|
|
|
|
|
|
|
# ---------------------------------------------------------------------
|
|
|
|
# Main weapon params
|
|
|
|
# ---------------------------------------------------------------------
|
|
|
|
@export var damage: int = 0
|
|
|
|
# cooldown interval in seconds
|
|
|
|
@export var cooldown: float = 0
|
|
|
|
# bullet speed in m/s
|
2025-01-31 19:19:38 +00:00
|
|
|
@export var bullet_speed: int = 200
|
2025-01-28 18:32:38 +00:00
|
|
|
@export var bullet_spread_script: GDScript
|
|
|
|
|
2025-01-28 09:51:45 +00:00
|
|
|
|
|
|
|
# Called when the node enters the scene tree for the first time.
|
|
|
|
func _ready() -> void:
|
|
|
|
pass # Replace with function body.
|
|
|
|
@onready var bullet_trace_distance: Node3D = $BulletTraceDistance
|
|
|
|
@onready var bullet_trail_end: Node3D = $BulletTrailEnd
|
2025-01-31 19:19:38 +00:00
|
|
|
@onready var gun_animation = $ShotAnimation
|
2025-01-28 09:51:45 +00:00
|
|
|
|
|
|
|
func shoot() -> Error:
|
|
|
|
var bullet_start_node: Node3D = bullet_trace_distance.find_child("Start")
|
|
|
|
var bullet_end_node: Node3D = bullet_trace_distance.find_child("End")
|
2025-01-31 19:19:38 +00:00
|
|
|
gun_animation.play("shot")
|
2025-01-28 09:51:45 +00:00
|
|
|
if bullet_start_node and bullet_end_node:
|
|
|
|
var path := "res://scenes/weapon/misc/bullet_trail_generic.tscn"
|
|
|
|
if not ResourceLoader.exists(path):
|
|
|
|
return ERR_DOES_NOT_EXIST
|
|
|
|
var scene: PackedScene = ResourceLoader.load(path)
|
|
|
|
if not scene.can_instantiate():
|
|
|
|
return ERR_CANT_OPEN
|
|
|
|
|
|
|
|
var node: MeshInstance3D = scene.instantiate()
|
|
|
|
node.init(bullet_start_node.position, bullet_end_node.position)
|
|
|
|
#var root := get_tree().get_root()
|
|
|
|
bullet_start_node.add_child(node)
|
|
|
|
return OK
|
|
|
|
else:
|
|
|
|
push_warning("Couldn't generate a bullet trace, no distance node found")
|
|
|
|
return ERR_BUG
|
|
|
|
# -- TODO: It should not be hardcoded
|
|
|
|
|
|
|
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
|
|
|
func _process(delta: float) -> void:
|
|
|
|
pass
|