CollisionComponent

Native collision component.

Provides access to a native collision component instance.

.TypeName: string 

.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:

1// Spans 1 unit on the x-axis, 2 on the y-axis, 3 on the z-axis.
2collision.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.

 1   // c belongs to group 2
 2   c.group = (1 << 2);
 3
 4   // c belongs to group 0
 5   c.group = (1 << 0);
 6
 7   // c belongs to group 0 *and* 2
 8   c.group = (1 << 0) | (1 << 2);
 9
10   (c.group & (1 << 2)) != 0; // true
11   (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:

1sphere.radius = 3.0;
2console.log(sphere.radius); // 3.0
3
4box.extents = [2.0, 2.0, 2.0];
5console.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:

1aabbCollision.radius = 2.0; // AABB fits a sphere of radius 2.0
2boxCollision.radius = 3.0; // Box now fits a sphere of radius 3.0, keeping orientation

.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.

ParamTypeDescription
outTDestination array/vector, expected to have at least 3 elements.
Template ParamType Definition
Textends NumberArray

.queryOverlaps() ⇒ CollisionComponent[] 

Query overlapping objects.

Usage:

1const collision = object.getComponent('collision');
2const overlaps = collision.queryOverlaps();
3for(const otherCollision of overlaps) {
4    const otherObject = otherCollision.object;
5    console.log(`Collision with object ${otherObject.objectId}`);
6}

Returns: Collision components overlapping this collider.