Bullet code won't work. Can any help or fix it?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By jhale
if Input.is_action_just_pressed("ui_down"):
	var spear = SPEAR.instance()
	spear.position = $Position2D.global_position

The code worked until I added the position line. Can anyone tell me why this has happened?

Is there an error-message?
Is Position2D a child of the node with this script?

whiteshampoo | 2020-06-24 19:27

Yes it is a child of the node with this script. There is no error message when I try and shoot.

jhale | 2020-06-24 23:13

:bust_in_silhouette: Reply From: Czselu349

I think you don’t have the Position2D as a direct child of the node that has this script. You may have to add it to your scene, or just add another path.
for example instead of the commend “$Position2D” you may have to use:


I’m just saying, that you can’t call a properity of a node, if it doesn’t exists on the path, that you’re giving to the function.
With this little information i could only guess the answer, but I hope it helped :wink: