Search Unity

Physics.IgnoreCollision for dots physics

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

  1. argibaltzi

    argibaltzi

    Joined:
    Nov 13, 2014
    Posts:
    220
    Hi

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

    petarmHavok

    Joined:
    Nov 20, 2018
    Posts:
    461
    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

    argibaltzi

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

    steveeHavok

    Joined:
    Mar 19, 2019
    Posts:
    481
    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;
    4.  
    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.         }
    31.  
    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. }
    42.  

    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.

    upload_2020-8-12_15-56-47.png

    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

    argibaltzi

    Joined:
    Nov 13, 2014
    Posts:
    220
    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

    Occuros

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