Collider
Descriptionβ
This component establishes a physics collider on an entity.
ColliderShapeβ
Type | Description |
---|---|
Box | Box |
Sphere | Sphere |
Plane | Plane |
Capsule | Capsule |
Cone | Cone |
Cylinder | Cylinder |
Propertiesβ
Name | Type | Default | Description |
---|---|---|---|
shape (Required) | ecs.ColliderShape | ecs.ColliderShape.Box | Supported types are available in ecs.ColliderShape |
width | number | 0 | Width of Box or Plane shapes. |
height | number | 0 | Height of Box, Plane, Capsule, Cone, or Cylinder shapes. |
depth | number | 0 | Depth of Box shape. |
radius | number | 0 | Radius of Sphere, Capsule, Cone, or Cylinder shapes. |
mass | number | 0 | Mass of the entity. Leave 0 to make static |
eventOnly | boolean | false | Should the object only dispatch collision events, and not physically respond |
gravityFactory | number | 1 | Factor of which to scale World gravity |
lockXAxis | boolean | false | Disables rotation on the X Axis |
lockYAxis | boolean | false | Disables rotation on the Y Axis |
lockZAxis | boolean | false | Disables rotation on the Z Axis |
friction | number | 0.5 | The amount of contact friction on the entity |
restitution | number | 0 | The bounciness of the entity |
linearDamping | number | 0 | The amount of air resistance while moving |
angularDamping | number | 0 | The amount of air resistance while rotating |
spinningFriction | number | 0 | The amount of friction on the entity while spinning |
Functionsβ
Getβ
Returns a read-only reference.
Example
ecs.Collider.get(world, component.eid)
Setβ
Ensures the component exists on the entity, then assigns the (optional) data to the component.
Example
ecs.Collider.set(world, component.eid, {
shape: 'ecs.ColliderShape.Box',
width: 0,
height: 0,
depth: 0,
radius: 0,
mass: 0,
eventOnly: false,
gravityFactory: 1,
lockXAxis: false,
lockYAxis: false,
lockZAxis: false,
friction: 0.5,
restitution: 0,
linearDamping: 0,
angularDamping: 0,
spinningFriction: 0
})
Mutateβ
Perform an update to the component within a callback function. Return true
to indicate no changes made.
Example
ecs.Collider.mutate(world, component.eid, (cursor) => {
cursor.mass = 5;
cursor.friction = 0.8;
return false;
})
Removeβ
Removes the component from the entity.
Example
ecs.Collider.remove(world, component.eid)
Hasβ
Returns true
if the component is present on the entity.
Example
ecs.Collider.has(world, component.eid)
Resetβ
Adds, or resets the component to its default state.
Example
ecs.Collider.reset(world, component.eid)
Advanced Functionsβ
Cursorβ
Returns a mutable reference. Cursors are reused so only one cursor for each component can exist at a time.
Example
ecs.Collider.cursor(world, component.eid)
Acquireβ
Same behavior as cursor, but commit must be called after the cursor is done being used.
Example
ecs.Collider.acquire(world, component.eid)
Commitβ
Called after acquire. An optional third argument determines whether the cursor was mutated or not.
Example
ecs.Collider.commit(world, component.eid)
ecs.Collider.commit(world, component.eid, false)
Dirtyβ
Mark the entity as having been mutated. Only needed in a specific case where systems are mutating data.
Example
ecs.Collider.dirty(world, component.eid)