CollisionComponent
Native collision component.
Provides access to a native collision component instance.
Static Members
Properties
Methods
- .getExtents<T>(out) ⇒ T
- .queryOverlaps() ⇒ CollisionComponent[]
Static Members
.TypeName: string
Properties
.collider: Collider
Collision component collider
.collider
Set collision component collider.
.extents: Float32Array
Equivalent to getExtents.
Note: Prefer to use getExtents for performance.
.extents
Set collision component extents.
If collider returns Sphere, only the first component of the passed vector is used.
Example:
// Spans 1 unit on the x-axis, 2 on the y-axis, 3 on the z-axis.
collision.extent = [1, 2, 3];
.group: number
Collision component group.
The groups is a bitmask that is compared to other components in queryOverlaps or the group in rayCast.
Colliders that have no common groups will not overlap with each other. If a collider has none of the groups set for rayCast, the ray will not hit it.
Each bit represents belonging to a group, see example.
// c belongs to group 2
c.group = (1 << 2);
// c belongs to group 0
c.group = (1 << 0);
// c belongs to group 0 *and* 2
c.group = (1 << 0) | (1 << 2);
(c.group & (1 << 2)) != 0; // true
(c.group & (1 << 7)) != 0; // false
.group
Set collision component group.
.radius: number
Get collision component radius.
Note: If collider is not Sphere, the returned value corresponds to the radius of a sphere enclosing the shape.
Example:
sphere.radius = 3.0;
console.log(sphere.radius); // 3.0
box.extents = [2.0, 2.0, 2.0];
console.log(box.radius); // 1.732...
.radius
Set collision component radius.
Note: If collider is not Sphere, the extents are set to form a square that fits a sphere with the provided radius.
Example:
aabbCollision.radius = 2.0; // AABB fits a sphere of radius 2.0
boxCollision.radius = 3.0; // Box now fits a sphere of radius 3.0, keeping orientation
.visualize: boolean
1.5.0+
Whether this collider is rendered in the debug visualization.
.visualize
1.5.0+
Set whether this collider is rendered in the debug visualization.
Methods
.getExtents<T>(out: T) ⇒ T
.getExtents() ⇒ Float32Array
Collision component extents.
If collider returns Sphere, only the first component of the returned vector is used.
Returns: The out parameter.
| Param | Type | Description |
|---|---|---|
out | T | Destination array/vector, expected to have at least 3 elements. |
| Template Param | Type Definition |
|---|---|
T | extends NumberArray |
.queryOverlaps() ⇒ CollisionComponent[]
Query overlapping objects.
Usage:
const collision = object.getComponent('collision');
const overlaps = collision.queryOverlaps();
for(const otherCollision of overlaps) {
const otherObject = otherCollision.object;
console.log(`Collision with object ${otherObject.objectId}`);
}
Returns: Collision components overlapping this collider.