@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
The options for the physics world.
Returns
PhysicsWorld
Overrides
Properties
dispose()?
readonlyoptionaldispose: (data) =>void
Defined in: src/ecs/system.ts:104
The function to run when the system is disposed.
Parameters
data
The data for the disposal.
Returns
void
Inherited from
keepOnClientSceneSwitch
readonlykeepOnClientSceneSwitch: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
readonlypriority: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
query
readonlyquery: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
queryKey
readonlyqueryKey: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
stateUpdate()?
readonlyoptionalstateUpdate: (data) =>void
Defined in: src/ecs/system.ts:97
The function to run on state updates.
Parameters
data
The data for the update.
Returns
void
Inherited from
type
readonlytype: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
update()?
readonlyoptionalupdate: (data) =>void
Defined in: src/ecs/system.ts:83
The function to run on updates.
Parameters
data
The data for the update.
Returns
void
Inherited from
GRAVITY_FORCE_SCALE
readonlystaticGRAVITY_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
Returns
void
Overrides
System.fixedUpdate
getGravity()
getGravity():
Vec2
Defined in: src/physics/world.ts:280
Gets the gravity of the physics world.
Returns
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
The minimum point of the AABB.
max
The maximum point of the AABB.
Returns
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
The center of the circle.
radius
number
The radius of the circle.
Returns
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
The start of the ray.
end
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
The origin of the ray.
dir
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
The origin of the ray.
dir
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
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
The start of the ray.
end
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
runEveryNthCall()
protectedrunEveryNthCall<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
setGravity()
setGravity(
gravity):void
Defined in: src/physics/world.ts:271
Sets the gravity of the physics world.
Parameters
gravity
The gravity to set.
Returns
void
getCollider()
staticgetCollider(entity):null|Collider
Defined in: src/physics/world.ts:50
Parameters
entity
Returns
null | Collider