27 lines
792 B
GDScript
27 lines
792 B
GDScript
extends Node3D
|
|
|
|
|
|
# Called when the node enters the scene tree for the first time.
|
|
func _ready() -> void:
|
|
pass # Replace with function body.
|
|
@onready var barrel: Node3D = $Barrel
|
|
|
|
func shoot() -> Error:
|
|
# -- TODO: It should not be hardcoded
|
|
var path := "res://scenes/weapon/guns/ak/bullet.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: Node3D = scene.instantiate()
|
|
var root := get_tree().get_root()
|
|
node.position = barrel.global_position
|
|
node.transform.basis = barrel.global_transform.basis
|
|
root.add_child(node)
|
|
return OK
|
|
|
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
|
func _process(delta: float) -> void:
|
|
pass
|