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

Procedural collision filtering... is it possible in Unity?

Discussion in 'Scripting' started by markt1964, Dec 24, 2015.

  1. markt1964

    markt1964

    Joined:
    Aug 30, 2011
    Posts:
    83
    When using physics layers are too limited and calling Physics.IgnoreCollision is not robust enough (because that causes the objects to ignore *all* collisions with eachother), is there any way at all to procedurally filter just a specific would-be collision from happening at all at the time it is about to otherwise occur?
     
  2. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    There is no collision-without-response (yet?) but you can do sweep tests. Also triggers are a horrible hack you can look into (on/off)
     
  3. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    Using triggers and coding all of your own collisions is the best I have come across so far. Its a pretty nasty hack, especially as we don't have all of the implementation details on how Unity actually handles collisions internally.
     
  4. markt1964

    markt1964

    Joined:
    Aug 30, 2011
    Posts:
    83
    Sweep tests on OnUpdate are too expensive (asymptotic to O(n^2)) and coding collision response myself in a trigger handler would result in having to manually compute all of the details that are already otherwise conveniently stored in a Collision class with normal collision processing, and would certainly be a lot slower than Unity's collision response system. Worse, if I wanted my collisions to look consistent, I would have to fall back on using such a system for every collision even if I otherwise did not require a custom filter for a given object, because otherwise some collisions would be processed by Unity, and some by me, and the results would be unlikely to look the same.

    I have just made a feature request for this, because it would be most useful.
     
    Kiwasi likes this.