Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Discussion How to make weapon pick-up systems like Counter Strike

Discussion in 'Scripting' started by teanteagame, Jul 31, 2023.

  1. teanteagame

    teanteagame

    Joined:
    Jul 15, 2019
    Posts:
    8
    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?
     
  2. tomfulghum

    tomfulghum

    Joined:
    May 8, 2017
    Posts:
    69
    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.
     
    Kurt-Dekker likes this.
  3. teanteagame

    teanteagame

    Joined:
    Jul 15, 2019
    Posts:
    8
    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.
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,713
    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.
     
    tomfulghum likes this.