Categories
A category
represents one or more categories that an entity can belong to.
Categories is primarily used with the physics engine to determine which entities can collide with each other.
Declaration
A category is declared using the category
keyword followed by an identifier.
The identifier must begin with an uppercase letter.
Categories can be declared as public using the pub
keyword,
which allows them to be accessed from all files in the program.
Otherwise they are private and can only be accessed from within the same file.
If two private categories have the same name but are in different files,
they are not the same category and will not interfere with each other.
pub category Category:Hero
category Category:AffectedByLava
Prefix the category with the keyword tangible
to make a category tangible,
meaning it will collide with other tangible categories by default.
By default, categories are not tangible.
pub tangible category Category:Hero
category Category:AffectedByLava
Manipulating categories
Categories can be combined using the |
operator.
this.Category = Category:Hero | Category:AffectedByLava
Call a.Overlaps(b)
to determine if there is any overlap between one set of categories and another.
if (this.Category.Overlaps(Category:Hero | Category:AffectedByLava)) {
Transmission { "This entity is either a hero or affected by lava!" }
}
Call a.Contains(b)
to determine if one set of categories contains another.
if (this.Category.Overlaps(Category:Hero | Category:AffectedByLava)) {
Transmission { "This entity is both a hero and affected by lava!" }
}
Working with categories
Categories can be assigned to the Category property of an entity to determine
which categories it belongs to.
This can affect whether it will be found by a Query(...)
.
Categories can also be passed into PolygonCollider to determine whether one collider can interact with another.