CollisionConfig class
Configuration for collision behavior.
Attach alongside Collider to control collision layer filtering and sensor behavior.
Layer/Mask System
Collision occurs when both entities agree to interact:
(A.layer & B.mask) != 0 && (B.layer & A.mask) != 0
- layer - What layers this entity belongs to (what it IS)
- mask - What layers this entity collides with (what it INTERACTS WITH)
Sensors
When isSensor is true, the entity generates CollisionEvents but doesn't block movement. Useful for triggers, transition zones, etc.
Defaults
Entities without CollisionConfig are treated as:
- layer: CollisionLayers.all (belongs to all layers)
- mask: CollisionLayers.all (collides with all layers)
- isSensor: false (blocks movement)
Example:
// Player - solid, collides with solid and trigger layers
entity.insert(CollisionConfig(
layer: GameLayers.player,
mask: GameLayers.solid | GameLayers.trigger | GameLayers.enemy,
));
// Transition zone - sensor that only interacts with player
entity.insert(CollisionConfig.sensor(
layer: GameLayers.trigger,
mask: GameLayers.player,
));
Constructors
- CollisionConfig({int layer = CollisionLayers.all, int mask = CollisionLayers.all, bool isSensor = false, bool blocksDynamic = false, Duration? yieldAfter})
-
Creates a collision configuration.
const
- CollisionConfig.sensor({int layer = CollisionLayers.trigger, int mask = CollisionLayers.all})
-
Creates a sensor configuration (generates events, no blocking).
const
- CollisionConfig.solid({int layer = CollisionLayers.solid, int mask = CollisionLayers.all, bool blocksDynamic = false, Duration? yieldAfter})
-
Creates a solid configuration (blocks movement).
const
Properties
- blocksDynamic → bool
-
Opt-in flag for dynamic-vs-dynamic blocking.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- isSensor → bool
-
If true, generates CollisionEvent but doesn't block movement.
final
- layer → int
-
Bitmask of layers this entity belongs to.
final
- mask → int
-
Bitmask of layers this entity collides with.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- yieldAfter → Duration?
-
After this much continuous contact with another dynamic body
that also has yieldAfter set, blocking between the two turns
off (they pass through each other) until they separate. When
they separate the yield resets and blocking resumes.
final
Methods
-
canCollideWith(
CollisionConfig other) → bool - Returns true if this entity can collide with another.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
override
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited