physics
Descriptionβ
This library has methods for applying physics and setting Colliders on Entities.
Functionsβ
applyForceβ
You can directly apply forces (linear and angular) to any entity with a physics collider. These forces are applied in the next physics simulation update, which takes place at regular intervals. The function accepts a 3D vector to define the force direction and magnitude.
This is dependent on the frequency of calls to requestAnimationFrame() or your devices refresh rate.
ecs.physics.applyForce(world, eid, forceX, forceY, forceZ) // -> void
applyImpulseβ
This function is used to apply a one-time instantaneous force to a physics collider, altering its velocity based on the given impulse vector. This method is useful for events that require a quick, single action response, such as jumping, punching, or a sudden push.
ecs.physics.applyImpulse(world, eid, impulseX, impulseY, impulseZ) // -> void
applyTorqueβ
You can directly apply forces (linear and angular) to any entity with a physics collider. These forces are applied in the next physics simulation update, which takes place at regular intervals. The function accepts a 3D vector to define the force direction and magnitude.
This is dependent on the frequency of calls to requestAnimationFrame() or your devices refresh rate.
ecs.physics.applyTorque(world, eid, torqueX, torqueY, torqueZ) // -> void
getWorldGravityβ
This is a simple getter function that returns the current force of gravity applied to every object in the scene. The return value might change depending on the time the function was executed.
ecs.physics.getWorldGravity(world) // -> number
registerConvexShapeβ
Register a convex shape.
ecs.physics.registerConvexShape(world, vertices) // -> eid of the registered shape
getLinearVelocityβ
Get the linear velocity of an entity.
ecs.physics.getLinearVelocity(world, eid) // -> number
setLinearVelocityβ
Set the linear velocity of an entity.
ecs.physics.setLinearVelocity(world, eid, velocityX, velocityY, velocityZ) // -> void
setWorldGravityβ
Set the world gravity.
ecs.physics.setWorldGravity(world, gravity) // -> void
unregisterConvexShapeβ
Unregister a convex shape.
ecs.physics.unregisterConvexShape(world, id) // -> void
Eventsβ
COLLISION_START_EVENTβ
Emitted when collision has begun with an entity.
ecs.physics.COLLISION_START_EVENT.data : { other }
Propertiesβ
Property | Type | Description |
---|---|---|
other | eid | The eid of the collided entity |
COLLISION_END_EVENTβ
Emitted when collision has stopped with an entity.
ecs.physics.COLLISION_END_EVENT.data : { other }
Propertiesβ
Property | Type | Description |
---|---|---|
other | eid | The eid of the collided entity |