Game.Common.CollisionMask
Assembly: Game
Namespace: Game.Common
Type: enum
Base: System.Enum (underlying type: System.Int32)
Summary:
CollisionMask is a bitflags enum used to classify collision layers (or collision masks) for game objects. The Flags attribute allows combinations of these values so a single mask can represent multiple collision layers (for example, an object that interacts with both Overground and Underground). These masks are typically used by collision checks, filtering queries, or physics/collision systems to decide which objects should be considered for interaction or contact.
Fields
-
OnGround = 1
Represents the ground collision layer. Use this flag for objects that live on or interact with the ground surface (e.g., sidewalks, ground-level props). -
Overground = 2
Represents the overground collision layer. Use this flag for objects above the ground (e.g., elevated roads, bridges, air objects). -
Underground = 4
Represents the underground collision layer. Use this flag for objects below the ground surface (e.g., tunnels, underground utilities). -
ExclusiveGround = 8
Represents a distinct ground-only layer used to mark objects that should be treated exclusively as ground collisions. This can be used to separate objects that must not be considered by mixed-layer collision logic or should be prioritized/filtered differently from the generic OnGround flag.
Properties
- N/A (enum type — individual named values are accessed directly)
Additional notes: because this is a [Flags] enum, values can be combined using bitwise operators to form composite masks (for example, CollisionMask.OnGround | CollisionMask.Overground).
Constructors
- N/A (enum types use default value construction; the underlying integer value corresponds to the declared flags)
Methods
- N/A (no custom methods defined; inherits standard System.Enum methods such as ToString, HasFlag, etc.)
Performance tip: prefer using bitwise checks like (mask & CollisionMask.OnGround) != 0 over Enum.HasFlag in performance-sensitive code.
Usage Example
// Combine flags to form a mask that includes both ground and overground
CollisionMask mask = CollisionMask.OnGround | CollisionMask.Overground;
// Check whether a mask includes OnGround
bool hasGround = (mask & CollisionMask.OnGround) != 0;
// or, equivalently (but slightly slower in general):
bool hasGroundAlt = mask.HasFlag(CollisionMask.OnGround);
// Add another flag
mask |= CollisionMask.Underground;
// Remove Overground flag
mask &= ~CollisionMask.Overground;
// Example function that filters objects by mask
bool ShouldCollide(CollisionMask objectMask, CollisionMask queryMask)
{
// return true if any of the queryMask layers overlap the object's mask
return (objectMask & queryMask) != 0;
}