How to make weapon pick-up systems like Counter Strike

I am working on a project to make a multiplayer fps game. I’m currently developing a weapon pick-up and drop system. I’d love to make the auto pick-up system like Counter-Strike, when the player is unarmed and approaches the weapon, the weapon will automatically add to his inventory. I tried using OnTriggerEnter() but weapons can always be picked up through walls and I don’t want that. Can anyone give me a suggestion?

The obvious solution is to make the triggers smaller so that they don’t clip through walls. If that’s not a viable solution, you can also just use a Raycast from the player to the weapon to check if there’s a wall in between before picking up the weapon.

1 Like

Smallen the trigger makes my character get harder to detect the weapon but using Raycast may be a good idea. However, this is a multiplayer project and I’m worried that players might be sharing weapons from a dropped weapon if I keep using the trigger method. Anyway, thanks for your suggestion.

That’s a separate problem. Don’t conflate that problem with your simple trigger + raycast situation.

Tom’s raycast suggestion is almost certainly the best way to go: if you can’t raycast and hit the thing, you can consider it isn’t reachable. This also works for weapons hiding behind crates and around corners / behind walls.

1 Like