I'm a beginner so I was following a tutorial of a shooter game, everything is working well, but my bullets don't come from the player, they come from de scene node. I check the scripts again and again but can't find where the problem is.
My scripts:
Arena script
extends Node2D
func _ready():
Global.node_creation_parent = self
func _exit_tree():
Global.node_creation_parent = null
global script
extends Node
var node_creation_parent = null
func instance_node(node, location, parent):
var node_instance = node.instance()
parent.add_child(node_instance)
node_instance.global_position = location
return node_instance
Player script
extends AnimatedSprite
var speed = 150
var velocity = Vector2()
var bullet = preload("res://scenes/bullet.tscn")
var cant_shoot = true
func _process(delta):
velocity.x = int(Input.is_action_pressed("move_right")) - int(Input.is_action_pressed("move_left"))
velocity.y = int(Input.is_action_pressed("move_down")) - int(Input.is_action_pressed("move_up"))
velocity = velocity.normalized()
global_position += speed * velocity * delta
if Input.is_action_pressed("click") and Global.node_creation_parent != null and cant_shoot:
Global.instance_node(bullet, global_position, Global.node_creation_parent)
$Reload_speed.start()
cant_shoot = false
func _on_Reload_speed_timeout():
cant_shoot = true