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. Join us on March 30, 2023, between 5 am & 1 pm EST, in the Performance Profiling Dev Blitz Day 2023 - Q&A forum and Discord where you can connect with our teams behind the Memory and CPU Profilers.
    Dismiss Notice

Physics.IgnoreCollision for dots physics

Discussion in 'Physics for ECS' started by argibaltzi, Aug 1, 2020.

  1. argibaltzi


    Nov 13, 2014

    How can i ignore collision between 2 colliders just like the Physics.IgnoreCollision?
  2. petarmHavok


    Nov 20, 2018
    On the PhysicsShapeAuthoring script, you have CollisionResponse - set it to CollisionResponse.None. These bodies will not collide, but you can still query them if you need to. Unfortunately, they will not collide with anything, not just between the 2.

    You can also go for collision filters if you need just the two of them not to collide, put them in different groups and make sure they don't collide with the group of the other one.
  3. argibaltzi


    Nov 13, 2014
    ok so the only way is through groups at the moment
    petarmHavok likes this.
  4. steveeHavok


    Mar 19, 2019
    Note that CollisionResponse.None will stop all collisions for that particular shape with every other shape. If you only want to stop collisions between 2 specific colliders then there are a few things you can do:
    1. Change the CollisionFilter information so they ignore each other as in the 2c3. Material Properties - Collision Filters demo.
    2. Disable the collision pair in the broadphase as in the 5. Modify/ModifyBroadphasePairs scene
    3. [HackTime] You could create a custom Joint with a single angular Constraint with unlimited range :)
    #3 uses the fact that 2 Jointed bodies have a flag to disable collisions between them. Deep in the simulation loop collisions pairs are skipped if this flag is set. However, we don't actually want our Joint to do any actual constraining!
    If you have copied the Joint creation and conversion code from the samples project you can easily add a new DisableCollisionJoint which adds an angular constraint with no limits e.g.

    Code (CSharp):
    1. using Unity.Collections;
    2. using Unity.Entities;
    3. using Unity.Mathematics;
    5. namespace Unity.Physics.Authoring
    6. {
    7.     // This Joint allows you to disable collisions between 2 bodies.
    8.     // The joint itself constrained no degrees of freedom.
    9.     public class DisableCollisionJoint : BaseJoint
    10.     {
    11.         public static PhysicsJoint CreateDisableCollisionJoint()
    12.         {
    13.             var constraints = new FixedList128<Constraint>();
    14.             constraints.Add(new Constraint
    15.             {
    16.                 ConstrainedAxes = new bool3(false),
    17.                 Type = ConstraintType.Angular,
    18.                 Min = -math.PI,
    19.                 Max = math.PI,
    20.                 SpringFrequency = Constraint.DefaultSpringFrequency,
    21.                 SpringDamping = Constraint.DefaultSpringDamping
    22.             });
    23.             var joint = new PhysicsJoint()
    24.             {
    25.                 BodyAFromJoint = BodyFrame.Identity,
    26.                 BodyBFromJoint = BodyFrame.Identity,
    27.             };
    28.             joint.SetConstraints(constraints);
    29.             return joint;
    30.         }
    32.         public override void Create(EntityManager entityManager, GameObjectConversionSystem conversionSystem)
    33.         {
    34.             conversionSystem.World.GetOrCreateSystem<EndJointConversionSystem>().CreateJointEntity(
    35.                 this,
    36.                 GetConstrainedBodyPair(conversionSystem),
    37.                 CreateDisableCollisionJoint()
    38.             );
    39.         }
    40.     }
    41. }

    Then in PhysicsJointConversionSystem.cs add an extra line to OnUpdate

                Entities.ForEach((DisableCollisionJoint joint) => { foreach (var j in joint.GetComponents<DisableCollisionJoint>()) CreateJoint(j); });

    You can then add the joint to an body and assigned the connected body to disable collisions between them.


    This is still doing some work deep in the simulation loop, but if this is considered a useful thing to add it could be significantly optimized.
    NotaNaN and Edy like this.
  5. argibaltzi


    Nov 13, 2014
    a lot of work to disable collision between 2 bodies when it could have been a lot simpler like in the default physics engine. i hope this feature is added sometime soon in dots
    petarmHavok, NotaNaN and Edy like this.
  6. Occuros


    Sep 4, 2018
    Has there been any update on this feature for 1.0 release?