Make it possible to dynamically set weapon parans
This commit is contained in:
41
scenes/weapon/generic_weapon_controller.gd
Normal file
41
scenes/weapon/generic_weapon_controller.gd
Normal file
@@ -0,0 +1,41 @@
|
||||
extends Node3D
|
||||
|
||||
# ---------------------------------------------------------------------
|
||||
# Main weapon params
|
||||
# ---------------------------------------------------------------------
|
||||
@export var damage: int = 0
|
||||
# cooldown interval in seconds
|
||||
@export var cooldown: float = 0
|
||||
# bullet speed in m/s
|
||||
@export var bullet_speed: int = 0
|
||||
|
||||
# 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
|
||||
|
||||
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")
|
||||
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
|
Reference in New Issue
Block a user