Picking up weapons

How can I make a weapon pickup? I tried to make it show the weapon like in the player weapons script when you touch it, but it didn’t work for some reason. does anyone have a script that does that?

There’s no intrinsic functionality in Unity to handle inventories, etc. – Unity is, essentially, agnostic about what 3d models are, do, represent. So you need to break what you want to do down into components:

  1. A weapon that lies around on the ground.
  2. A weapon that is in the player’s hand. (Possibly the same model as above, but now parented to the player’s hand, etc.)
  3. Some internal representation of whether a player has a weapon in their inventory.
  4. Code to manage inventories, place weapons in a player’s hand, etc.

So in overview:
The weapon on the ground needs to have some kind of collision detection, either to detect if the player walks into it (Quake-style) or clicks on it (World of Warcraft, say, style).

When the weapon is collided with (by the player) or clicked on (and the player is close enough) it disappears, and is now internally represented as being in the player’s inventory. (In Quake-style games, it would become equipped IF the player didn’t already have a weapon of that kind.)

If the player equips the weapon, it needs to be parented to the player’s hand (and its position and orientation finessed correctly) or the first person controller (much easier :slight_smile: ) or whatever, made visible (and any no-longer-in-use weapon made invisible) etc.

So, it’s a bit involved :slight_smile:

If you look at the old demo with the robots on the island, all of this is implemented there.

Excellent! It works! Thanks! :wink:

podperson: Where can you find “the old demo with the robots on the island”? I’m trying to set up something similar and it would be great see that example.

I believe that podperson was refering to the FPS tutorial which can be found here. http://unity3d.com/support/resources/assets/unity1xresources

Note however that since unity moved from 1.x to 2.x, the tutorial has become slightly broken.

I thought you were talking about a different one. Did this one. Was really good but has some errors with it. I’ve been trying to come up with a way to find a weapon and pick it up which adds to the inventory ie. key 1 is your basic weapon and key 2 gets the pickup weapon.