How to change weapons (pick up)

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By abbos

How to change weapons (pick up)

:bust_in_silhouette: Reply From: Bernard Cloutier

I assume you’ve got nodes arranged something like:

- Player
    - WeaponSlot
        - Weapon

It’s probably not like this, but this node structure is just for example (since you haven’t shown your scene tree or your code).

If you want to change your weapon, you’d simply remove the child node of WeaponSlot, and then add the new weapon node as a child of it.

Ex: In your player script

func change_weapon(newWeapon):
    var currentWeapon = $WeaponSlot.get_child(0)
    $WeaponSlot.remove_child(currentWeapon )

If you wonder how to do pickups in general, check out this page of the godot fps tutorial:

The tutorial also covers switching weapons, although the 3 weapons are always in the player’s “backpack”.

I suggest you share some screenshots of your editor and paste in your current scripts in order to get more helpful answers. If you want more people to help you, you have to be prepared to go into more details with your questions.