Ir al contenido principal

Colisionador

Descripción

Este componente establece un colisionador de física en una entidad.

ColliderShape

TipoDescripción
CajaCaja
EsferaEsfera
PlanoPlano
CápsulaCápsula
ConoCono
CilindroCilindro

ColliderType

TipoDescripción
EstáticoSe aplica a un objeto que no se mueve bajo simulación y se comporta como si tuviera masa infinita
DinámicoSe aplica a un objeto real totalmente simulado al que afectan las fuerzas, la gravedad y las colisiones.
CinemáticaSe aplica a un objeto cuyo movimiento no se ve afectado por las fuerzas, sino que está totalmente controlado mediante programación por el usuario. A diferencia de los cuerpos estáticos, los cuerpos cinemáticos pueden moverse y afectar a otros cuerpos dinámicos mediante colisiones.

Propiedades

PropiedadTipoPor defectoDescripción
typeecs.ColliderTypeecs.ColliderType.StaticSupported types include static, dynamic, and kinematic
shapeecs.ColliderShapeecs.ColliderShape.BoxSupported shape types include geometries and auto generated shapes from meshes
widthnumber0Width of Box or Plane shapes
heightnumber0Height of Box, Plane, Capsule, Cone, or Cylinder shapes
depthnumber0Depth of Box shape
radiusnumber0Radius of Sphere, Capsule, Cone, or Cylinder shapes
massnumber0Mass of the entity
eventOnlybooleanfalseDetermines if the object should only dispatch collision events, and not physically respond
gravityFactornumber1Factor of which to scale the world’s gravity
lockXAxisbooleanfalseDisables rotation on the X Axis
lockYAxisbooleanfalseDisables rotation on the Y Axis
lockZAxisbooleanfalseDisables rotation on the Z Axis
frictionnumber0.5The amount of contact friction on the entity
restitutionnumber0The bounciness of the entity, negative values absorb impact
linearDampingnumber0The amount of air resistance while moving
angularDampingnumber0The amount of air resistance while rotating
lockXPositionbooleanfalsePrevents movement of the collider along the X-axis
lockYPositionbooleanfalsePrevents movement of the collider along the Y-axis
lockZPositionbooleanfalsePrevents movement of the collider along the Z-axis
highPrecisionbooleanfalseEnables continuous collision detection to increase precision of collision events
offsetXnumber0Local X offset of the collider shape from the object origin
offsetYnumber0Local Y offset of the collider shape from the object origin
offsetZnumber0Local Z offset of the collider shape from the object origin

Funciones

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.Sphere,
type: ecs.ColliderType.Static,
radius: 1,
mass: 0,
eventOnly: false,
gravityFactory: 1,
lockXAxis: false,
lockYAxis: false,
lockZAxis: false,
friction: 0.5,
restitution: 0,
linearDamping: 0,
angularDamping: 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)