Search Unity

Item pick up colliders question

Discussion in 'Physics' started by nathanjams, Mar 4, 2018.

  1. nathanjams

    nathanjams

    Joined:
    Jul 27, 2016
    Posts:
    304
    hey, everyone

    Kind of a general question here, I’m hoping someone can give some advice.

    At the moment all of my pickup items have a rigidbody component and box collider. The issue is that the the player’s movement is blocked by the box collider, even if it’s a small object.

    I was thinking about setting the pick up items to a unque layer that is detectable by the raycast but does not physically interact with the player (changed in the physics manager). This way the player would not by hindered by the collider but still be able to interact with the items. Is there any reason not to do this?

    Or, if anyone has a best practice, or a link to a best practice, for pickup items I would be most grateful.

    Thanks in advance

    Nathan
     
  2. telecaster

    telecaster

    Joined:
    Jan 6, 2013
    Posts:
    29
    Layers are good practice. They improve performance too :)

    For new Unity users: Use the Edit -> Projects Settings -> Physics to identify which layers can interact with which other layer. For example you can still have a ray-cast target, without picking up player body collisions. Also great to define play areas but permit shooting.
     
    nathanjams likes this.
  3. nathanjams

    nathanjams

    Joined:
    Jul 27, 2016
    Posts:
    304
    I was thinking that it would be an improvement but I haven’t really seen this applied before so I was wondering if there was an unforeseen issue with this. So thanks for the confirmatiom @telecaster .
     
  4. BrandyStarbrite

    BrandyStarbrite

    Joined:
    Aug 4, 2013
    Posts:
    2,076
    nathanjams and Tset_Tsyung like this.
  5. Tset_Tsyung

    Tset_Tsyung

    Joined:
    Jan 12, 2016
    Posts:
    411
    BrandyStarbrire beat me to the same thought, lol.

    Unless you NEED the pick up item to be able to roll and bounce... but even then you could have a physics collider around the object and then ALSO have a larger trigger collider to allow the player/character to pickup the item BEFORE hitting the actual collider.

    ALL the best with it.
     
    nathanjams and BrandyStarbrite like this.
  6. Keita-kun

    Keita-kun

    Joined:
    Aug 20, 2017
    Posts:
    36
    Hi nathanjams,

    On the same lane as Tset_Tsyung.

    Question A: physics makes pickup to act as an obstacle, it suppose to disappear when pickedup or if player can't pickup more it's given that the player mass would be greater than the item' mass. The player can just run into it and voila out of the way.

    Question B: if your willing to go that far as adjusting physics and raycasting... wouldn't it be simple to just remove the rigidboy and check trigger on the collider and the pickup mechanism would be processed through the onTriggerEnter / OntriggerExit depending how the item should behave.

    By the time you have found the best practice for your game but just in case. the best way to do so is to have some interaction behavior that you can adjust to the object you're working with this includes a custom collider which act as a trigger and the code to execute depending on the object. This way object can still act and response to physics and also interact with the play ie:disable physics when Interacting with player / enable when interacting anything else.
    cheers