0 votes

Hello wonderful members of the community, im here to ask about the title basically.

Im making a top-down 2D action game, with a system of picking up and dropping weapons.

I could manage to make a pistol which starts on the floor, and the player can pick up and drop, this works great, but now i tried making the enemies drop their weapons when they die, using the same method for the player dropping.

This creates another "Pistol (pickup)" in the world BUT after that i always pick up "that" pistol, even if im standing on the other one.

The relevant code is the following:

var ppistol = preload("res://Pistol (pickup).tscn")

This happens when the player right clicks, while holding a pistol:

var drop = ppistol.instance() 

Then when the player weapon's raycast hits an enemy:


(I didnt write a "set_position" for this one yet)

Anyways... as you can see, both time i use "getnode("/root/World").addchild(ppistol.instance())" to spawn a pistol, so im guessing this needs to be different.

The only solution i could come up with was add several vars named "ppistol1" "ppistol 2" and so on, but this is very bad code and im sure there are other, much better, ways that i havent learned yet.

Thanks in advance!

in Engine by (298 points)

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.