Skip to content

@emile/engine


@emile/engine / physics/world / PhysicsWorld

Class: PhysicsWorld ​

Defined in: src/physics/world.ts:40

Represents a physics world.

The physics world has a system priority of 0. You can give your systems a higher priority to run before the physics world.

Extends ​

Constructors ​

new PhysicsWorld() ​

new PhysicsWorld(options): PhysicsWorld

Defined in: src/physics/world.ts:78

Creates a new physics world.

Parameters ​

options ​

PhysicsWorldOptions

The options for the physics world.

Returns ​

PhysicsWorld

Overrides ​

System.constructor

Properties ​

dispose()? ​

readonly optional dispose: (data) => void

Defined in: src/ecs/system.ts:104

The function to run when the system is disposed.

Parameters ​

data ​

SystemUpdateData

The data for the disposal.

Returns ​

void

Inherited from ​

System.dispose


keepOnClientSceneSwitch ​

readonly keepOnClientSceneSwitch: boolean = false

Defined in: src/ecs/system.ts:60

Whether the system should be kept on the client side (not removed) when switching scenes.

This is useful for systems that need to persist across scene changes, such as the renderer, physics world and scene graph.

Inherited from ​

System.keepOnClientSceneSwitch


priority ​

readonly priority: number

Defined in: src/ecs/system.ts:44

The priority of the system.

Systems with a higher priority will run before systems with a lower priority.

Inherited from ​

System.priority


query ​

readonly query: EntityQuery

Defined in: src/ecs/system.ts:28

The query to match entities.

An empty query will match all entities.

This should not be changed after the system is created.

Inherited from ​

System.query


queryKey ​

readonly queryKey: string

Defined in: src/ecs/system.ts:37

The key of the query.

This is used internally by the registry.

Do not change this value.

Inherited from ​

System.queryKey


stateUpdate()? ​

readonly optional stateUpdate: (data) => void

Defined in: src/ecs/system.ts:97

The function to run on state updates.

Parameters ​

data ​

SystemUpdateData

The data for the update.

Returns ​

void

Inherited from ​

System.stateUpdate


type ​

readonly type: SystemType

Defined in: src/ecs/system.ts:53

The type of the system.

This should not be changed after the system is created.

Note ​

This is used to determine if the system should run on the client, server, or both.

Inherited from ​

System.type


update()? ​

readonly optional update: (data) => void

Defined in: src/ecs/system.ts:83

The function to run on updates.

Parameters ​

data ​

SystemUpdateData

The data for the update.

Returns ​

void

Inherited from ​

System.update


GRAVITY_FORCE_SCALE ​

readonly static GRAVITY_FORCE_SCALE: number

Defined in: src/physics/world.ts:48

This is the scaling factor applied to the gravity force.

This allows you to use reasonable values for gravity in your game (e.g. 9.81) and have them converted to the very small force values for the physics engine.

You don't need to change this, just change the gravity in the physics world options.

Methods ​

fixedUpdate() ​

fixedUpdate(__namedParameters): void

Defined in: src/physics/world.ts:98

The function to run on fixed updates.

Parameters ​

__namedParameters ​

SystemUpdateData

Returns ​

void

Overrides ​

System.fixedUpdate


getGravity() ​

getGravity(): Vec2

Defined in: src/physics/world.ts:280

Gets the gravity of the physics world.

Returns ​

Vec2

The gravity of the physics world.


queryAABB() ​

queryAABB(min, max): QueryResult[]

Defined in: src/physics/world.ts:421

Queries the world for bodies that are inside an AABB.

Parameters ​

min ​

Vec2

The minimum point of the AABB.

max ​

Vec2

The maximum point of the AABB.

Returns ​

QueryResult[]

The bodies that intersect with the AABB.


queryCircle() ​

queryCircle(center, radius): QueryResultWithCollision[]

Defined in: src/physics/world.ts:389

Queries the world for bodies that intersect with a circle.

Parameters ​

center ​

Vec2

The center of the circle.

radius ​

number

The radius of the circle.

Returns ​

QueryResultWithCollision[]

The bodies that intersect with the circle.


queryRay() ​

Call Signature ​

queryRay(start, end, entities?): RayCol[]

Defined in: src/physics/world.ts:293

Queries the world for bodies that intersect with a ray.

Parameters ​
start ​

Vec2

The start of the ray.

end ​

Vec2

The end of the ray.

entities? ​

Iterable<string, any, any>

The entities to query. Optional. Defaults to all physics entities. Can improve performance if you only want to check a subset of entities.

Returns ​

RayCol[]

The bodies that intersect with the ray.

Call Signature ​

queryRay(origin, dir, len, entities?): RayCol[]

Defined in: src/physics/world.ts:305

Queries the world for bodies that intersect with a ray.

Parameters ​
origin ​

Vec2

The origin of the ray.

dir ​

Vec2

The direction of the ray.

len ​

number

The length of the ray.

entities? ​

Iterable<string, any, any>

The entities to query. Optional. Defaults to all physics entities. Can improve performance if you only want to check a subset of entities.

Returns ​

RayCol[]

The bodies that intersect with the ray.


queryRayQuick() ​

Call Signature ​

queryRayQuick(origin, dir, len, entities?): RayColSimple[]

Defined in: src/physics/world.ts:341

Queries the world for bodies that intersect with a ray.

This is a quick version of the queryRay method that does not return intersection information.

Parameters ​
origin ​

Vec2

The origin of the ray.

dir ​

Vec2

The direction of the ray.

len ​

number

The length of the ray.

entities? ​

Iterable<string, any, any>

The entities to query. Optional. Defaults to all physics entities. Can improve performance if you only want to check a subset of entities.

Returns ​

RayColSimple[]

Call Signature ​

queryRayQuick(start, end, entities?): RayColSimple[]

Defined in: src/physics/world.ts:352

Queries the world for bodies that intersect with a ray.

This is a quick version of the queryRay method that does not return intersection information.

Parameters ​
start ​

Vec2

The start of the ray.

end ​

Vec2

The end of the ray.

entities? ​

Iterable<string, any, any>

The entities to query. Optional. Defaults to all physics entities. Can improve performance if you only want to check a subset of entities.

Returns ​

RayColSimple[]


runEveryNthCall() ​

protected runEveryNthCall<T>(n, callback): T

Defined in: src/ecs/system.ts:112

Runs a callback every nth call. This is useful for reducing the frequency of certain updates that don't need to run every frame, such as expensive calculations or updates that only need to happen periodically.

Type Parameters ​

T ​

T extends (...args) => void

Parameters ​

n ​

number

The nth time to execute the callback, 2 will execute the callback on every 2nd call

callback ​

T

The callback to execute

Returns ​

T

Inherited from ​

System.runEveryNthCall


setGravity() ​

setGravity(gravity): void

Defined in: src/physics/world.ts:271

Sets the gravity of the physics world.

Parameters ​

gravity ​

Vec2

The gravity to set.

Returns ​

void


getCollider() ​

static getCollider(entity): null | Collider

Defined in: src/physics/world.ts:50

Parameters ​

entity ​

Entity

Returns ​

null | Collider