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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

character controller - ignore collision based on tags

Discussion in 'Scripting' started by Raybrand, Mar 17, 2014.

  1. Raybrand

    Raybrand

    Joined:
    Feb 6, 2012
    Posts:
    98
    hi, im want to make a feature where the player can move through objects but not walls or the terrain

    I found Physics.IgnoreCollision in the documentation but how do I make it so that it ignores collides based on their tag.
     
  2. rrh

    rrh

    Joined:
    Jul 12, 2012
    Posts:
    331
    Maybe instead assign layers for Terrain, Player, Objects. Then in the Physics settings you can set with layers collide with each other and which don't.
     
  3. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,380
    You can't by tags, it's by layer.

    It's done by layer, because layers are done by a bit mask, which can be done efficiently in the engine. Tags on the other hand are just strings, which can be expensive to mask.
     
  4. Raybrand

    Raybrand

    Joined:
    Feb 6, 2012
    Posts:
    98
    ok, thanks for that
    I've just briefly gone over layers and have made some for the environment and items but what do I type in script to trigger this effect. Looking at the documentation I found-
    Physics.IgnoreLayerCollision(int1, int2, bool)
    im guessing that int1 is the player and int2 is the layer with the colliders I want to ignore but why are they integers when my layers have names?