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

Ignoring player vs object collision but allowing interaction

Discussion in 'Scripting' started by misterlee, Mar 6, 2015.

  1. misterlee

    misterlee

    Joined:
    Sep 19, 2014
    Posts:
    54
    I'm having an issue where I have my character moving around and there are various objects to pick up and/or interact with. The problem is I don't want the player to knock into the objects and have them rolling around, or even worse block the player. So I'd like to not have collision detection between the objects and player, which is totally possible with layers as I have tried, but then I also can't interact with the objects to pick them up. Putting a separate trigger on the object on a different layer only allows me to pick up the trigger object, not the whole object.

    I know people have asked similar questions, but it's usually regarding players vs enemies, which would work with layers as you don't need to pick enemies up (usually!), but doesn't work for my scenario where I have to pick the object up and take it with me.

    Is there some way around this or am I stuck with knocking into everything?
     
  2. Tomnnn

    Tomnnn

    Joined:
    May 23, 2013
    Posts:
    4,148
    There's a physics function to make two colliders not interact. Look here. Raycasts for interaction should still hit the objects.
     
  3. _met44

    _met44

    Joined:
    Jun 1, 2013
    Posts:
    633
    Do the trigger technic but have a script with a gameObject parameter to indicate the root of the object, or use transform.root if your objects aren't parented under something, otherwise choose as convention that the parent of the trigger is the object to pick up...
     
  4. misterlee

    misterlee

    Joined:
    Sep 19, 2014
    Posts:
    54
    Thanks Tomnnn that's useful to know, I hadn't seen the 'ignoreCollision' thing before but I don't think it will help me since it only works with the gameObject and one other specified gameObject, I need to not collide with multiple objects in the same level. And if I use the ignoreLayerCollision then it's the same problem as changing the layer physics in the inspector - I won't get the triggers :(

    _met44... to be honest I'm not really sure what you're saying for the most part, but I'll look at picking up the parent of the trigger as you mentioned. Don't know how to do that yet but at least I have something to try :)
     
  5. _met44

    _met44

    Joined:
    Jun 1, 2013
    Posts:
    633
    transform.parent for the parent and transform.root for the root ;)
     
  6. Tomnnn

    Tomnnn

    Joined:
    May 23, 2013
    Posts:
    4,148
    Oh. You can ignore physics on 1 layer and have a child of the object contain the trigger collider and be on a different layer.