Ignoring collision between specific entities

I need to ignore collision between several colliders, which are calculated during runtime. In MonoBehaviour we used Physics.IgnoreCollision method, and it gets the job done, but I failed to find this method for DOTS Physics. Are there any ways of replicating this behaviour in DOTS?

2 Likes

GroupIndex can often be used for this

@CunningFox146 :
You can use the CollisionFilter in your collider for this purpose, as @tertle pointed out.
Have a look at its scripting API documentation.

Every collider holds a collision filter (see Collider.Set/GetCollisionFilter).
You can use the CollisionFilter.BelongsTo property to assign the given collider to different categories (or layers as in standard GameObjects).
With the CollisionFilter.CollidesWith property you can enable or disable collision of this collider with different such categories (or layers).
Both properties are bitmasks that you can modify using standard bit manipulation, e.g., setting the n’th bit in one of these properties using property |= 1 << n.

Note that if the collision filter in one of two overlapping colliders dictates that it should not collide with the other, then the collision is disabled. In other words, the filters in both colliders need to indicate that a collision should occur for the overlapping collider pair to actually collide.

Finally, the CollisionFilter.GroupIndex that @tertle pointed out above allows you to further group colliders and override their filter behavior altogether. If the GroupIndex is non-zero the following behavior is observed:

  • If in a pair of overlapping colliders, both colliders have the same positive GroupIndex value, they always collide.

  • Contrary, if in a pair of overlapping colliders, both colliders have the same negative GroupIndex value, they never collide.

Let me know if this helps.

A.Value.SetCollisionFilter(new CollisionFilter
                    {
                        BelongsTo = (uint)CollisionFilterHelper.Test1,
                        CollidesWith = (uint)CollisionFilterHelper.Test2
                    });
[/代码]

[code=CSharp]
B.Value.SetCollisionFilter(new CollisionFilter
                    {
                        BelongsTo = (uint)CollisionFilterHelper.Test2,
                        CollidesWith = (uint)CollisionFilterHelper.other
                    });
[/代码]

I would like to ask, the pseudo code is as above, Test1 is eager to collide with test2, and test2 is eager to collide with other. In this case, will test1 still collide with test2?

Have a look at the collision filter section in the official documentation here.
I hope it will clarify the behaviour.

For one, the BelongsTo and CollidesWith fields are bitfields and don’t work as implied in your code snippet.

The document is great, thank you

1 Like