Struct CollisionFilter
- Namespace
- Box3D
- Assembly
- Box3D.NET.dll
Controls which shapes are allowed to collide with each other.
public readonly record struct CollisionFilter : IEquatable<CollisionFilter>Implements
Inherited Members
Examples
Giving a player its own category and letting it collide only with the world and with enemies:
[Flags]
enum Layers : ulong
{
World = 1 << 0,
Player = 1 << 1,
Enemy = 1 << 2,
Debris = 1 << 3,
}
var filter = new CollisionFilter
{
Categories = (ulong)Layers.Player,
CollidesWith = (ulong)(Layers.World | Layers.Enemy),
};
Stopping a ragdoll from colliding with itself, without touching any masks:
var filter = CollisionFilter.Default with { Group = -ragdollIndex };
Remarks
Two shapes collide when each one's Box3D.CollisionFilter.Categories appears in the other's Box3D.CollisionFilter.CollidesWith mask. The test is symmetric: both directions must agree, so making one shape ignore another is enough to disable the pair.
Box3D.CollisionFilter.Group overrides the masks entirely when it is non-zero, which is the cheap way to express "these objects never collide with each other" without spending a category bit on them.
The same filter applies to queries such as ray casts, not only to shape-versus-shape collision.
Constructors
- CollisionFilter(ulong, ulong, int)
-
Initializes a new instance of the Box3D.CollisionFilter struct.
Properties
- Categories
-
Gets the categories this shape belongs to. Usually a single bit.
- CollidesWith
-
Gets the categories this shape is willing to collide with.
- Default
-
Gets a filter that belongs to every category and collides with everything.
- Group
-
Gets the collision group. Shapes sharing a negative group never collide; shapes sharing a positive group always collide. Zero has no effect.