Physics.IgnoreCollision for dots physics

Hi

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

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.

ok so the only way is through groups at the moment

1 Like

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:

#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.

using Unity.Collections;
using Unity.Entities;
using Unity.Mathematics;

namespace Unity.Physics.Authoring
{
    // This Joint allows you to disable collisions between 2 bodies.
    // The joint itself constrained no degrees of freedom.
    public class DisableCollisionJoint : BaseJoint
    {
        public static PhysicsJoint CreateDisableCollisionJoint()
        {
            var constraints = new FixedList128<Constraint>();
            constraints.Add(new Constraint
            {
                ConstrainedAxes = new bool3(false),
                Type = ConstraintType.Angular,
                Min = -math.PI,
                Max = math.PI,
                SpringFrequency = Constraint.DefaultSpringFrequency,
                SpringDamping = Constraint.DefaultSpringDamping
            });
            var joint = new PhysicsJoint()
            {
                BodyAFromJoint = BodyFrame.Identity,
                BodyBFromJoint = BodyFrame.Identity,
            };
            joint.SetConstraints(constraints);
            return joint;
        }

        public override void Create(EntityManager entityManager, GameObjectConversionSystem conversionSystem)
        {
            conversionSystem.World.GetOrCreateSystem<EndJointConversionSystem>().CreateJointEntity(
                this,
                GetConstrainedBodyPair(conversionSystem),
                CreateDisableCollisionJoint()
            );
        }
    }
}

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.

2 Likes

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

3 Likes

Has there been any update on this feature for 1.0 release?