If you want the player to immediately pick up the weapon when the player walks through the weapon, then set up the weapon with an Area
node. When the player walks through the weapon, have a script on the weapon node react to the player walking through the weapon. The script could have some like this in it (though not exactly this code because your project setup will probably be different):
# Don't forget to connect the Area signal "body_entered" to the weapon node
_on_area_entered(body):
# The player's script has the function "pick_up_weapon()".
if body is player and body.has_method("pick_up_weapon"):
# The "pick_up_weapon()" function would add the weapon to the player's inventory.
body.pick_up_weapon(some_weapon)
If the player needs to press a key/button to pick up the weapon after walking through it, use something like this code (though not exactly this code because, again, your game is probably setup differently):
# In the weapon script, the weapon has to tell the player script that the weapon's Area has been entered. Again, don't forget to connect the "body_entered" signal.
_on_area_entered(body):
# The player's script needs to keep track of whether it has entered the weapon's Area.
if body is player and player.has("weapon_area_entered"):
# This assigns "true" to the "weapon_area_entered" variable in the player's script.
body.weapon_area_entered = true
# We also need to have a variable to save which weapon it is.
body.weapon_currently_selected = "mcguffin"
# In the player's script.
_unhandled_input(event):
# The player presses the key/button to pick up the weapon.
if event is InputEvent and event.is_action_pressed("action_key"):
# The variable "weapon_currently_selected" needs to have something assigned to it.
if weapon_currently_selected:
# Add the weapon to the inventory.
inventory.push_back(weapon_currently_selected)
I hope this is a good starting point for developing the "pickup stuff" mechanic in your game.