Skip to main content

Physics

Categories

Category:All -> categories
Category:None -> categories

The Category:All constant includes all categories, whereas the Category:None constant represents no categories.

AfterCollide

await this.AfterCollide<Id?> -> entity

Waits until the end of any collision involving the collider belonging to this entity with the given Id. A collision ends once the two colliders involved are no longer in contact. If this is nullish, waits forever (in this case, the behavior will be released from memory since it will never return).

ApplyImpulse

body.ApplyImpulse(impulse)

Applies an impulse to the body, changing its velocity. The change in the velocity will equal the impulse divided by the body's mass. impulse must be a vector. If any parameter is nullish, does nothing.

ApplyTurningImpulse

body.ApplyTurningImpulse(turningImpulse)

Applies a turning impulse to the body, changing its turn rate. The change in the velocity will equal the turning impulse divided by the body's mass. turningImpulse must be a Number. If any parameter is nullish, does nothing.

BeforeCollide

await this.BeforeCollide<Id?> -> entity

Waits until the start of any collision involving the collider belonging to this entity with the given Id. A collision starts once the two colliders involved come into contact. If this is nullish, waits forever (in this case, the behavior will be released from memory since it will never return).

Body

this.Body([pos, velocity?=, heading?, turnRate?, immovable?, noRotation?, 
bullet?])
delete this.Body

Creates or replaces an entity's body. A body defines the physical position and velocity of an entity. Many things can be attached to a body, for example colliders, sprites, and sounds, to name a few.

  • this (Entity): the entity to add a Body to. If the entity already has a Body, it will be replaced. If this is nullish, this function does nothing.
  • pos (Vector): the position of the body.
  • heading (Number): the angle of the body, in radians.
  • velocity (Vector): the velocity of the body.
  • turnRate (Number): the rate at which the body turns in radians per second.
  • immovable (Boolean): if true, the body will not change its velocity after colliding with other bodies.
  • noRotation (Boolean): if true, the body will not change its heading after collding with other bodies.
  • bullet (Boolean): if true, the body will use continuous collision detection. This more computationally expensive, but ensures that a fast-moving body (like a bullet or projectile) does not tunnel through other bodies.

Category

this.Category -> categories
this.Category = categories
delete this.Category -> categories

Gets, sets or deletes the categories of this entity. delete Category will return the previous category, or undefined if the entity had no category assigned previously.

If entity is nullish, will do nothing and/or return undefined.

Category:Tangible

Category:Tangible -> categories

Returns the set of all categories declared with tangible category.

DecaySpeed

body.DecaySpeed([speedDecay?])
delete body.DecaySpeed

Makes the speed of body decay by a certain proportion after the physics simulation phase of each tick.

  • body (Entity): The entity to modify. If nullish, this function will do nothing.
  • speedDecay (Number): The rate at which the body's speed decays. Should be a value between 0 and 1. Defaults to the physics.speedDecay setting in easel.toml or 0.05 if not specified.

DecayTurnRate

body.DecayTurnRate([turningDecay?])
delete body.DecayTurnRate

Makes the turn rate of body decay by a certain proportion after the physics simulation phase of each tick.

  • body (Entity): The entity to modify. If nullish, this function will do nothing.
  • turningDecay (Number): The rate at which the body's turn rate decays. Should be a value between 0 and 1. Defaults to the physics.turningDecay setting in easel.toml or 0.5 if not specified.

ForcefulStep

body.ForcefulStep(step)

Applies a once-off force to move the body's position by the given step during the next physics simulation. The force will be added at the start of the physics simulation and then the opposite force will be applied at the end, so it will cancel out. The body will collide like normal during the physics simulation, and so this force may be transferred to other bodies. This allows for realistic simulation of charging into objects and sending them crashing backward, for example.

step must be a Vector. If any parameter is nullish, does nothing.

ForcefulTurn

body.ForcefulTurn(step)

Applies a once-off force to rotate the body's heading by the given step during the next physics simulation. The force will be added at the start of the physics simulation and then the opposite force will be applied at the end, so it will cancel out. The body will collide like normal during the physics simulation, and so this force may be transferred to other bodies. This allows for realistic simulation of swinging a sword and hitting objects, for example.

step must be a Number. If any parameter is nullish, does nothing.

Heading

body.Heading -> number

Gets the current heading of the body, in radians. If body is nullish or refers to an entity with no body, returns undefined.

body.Heading = value

Sets the current heading of the body, in radians. If body refers to an entity that does not yet have a body, a immovable body is first created, then assigned the new heading. If body is nullish, does nothing.

LimitSpeed

body.LimitSpeed([maxSpeed])
delete body.LimitSpeed

Limits the speed of body.

  • body (Entity): The entity to modify. If nullish, this function will do nothing.
  • maxSpeed (Number): The maximum speed of the body. null means no maximum speed.

LocatePerimeterPoint

body.LocatePerimeterPoint(edgeFraction, radiusFraction?=) -> vector

Returns a point within the perimeter of an entity. The perimeter must have been assigned previously using the PolygonPerimeter function, otherwise this will just return the center of the entity's body.

The edgeFraction parameter is a value between 0 and 1 that represents the position along the edge of the perimeter.

The radiusFraction parameter is a value between 0 and 1 that represents the distance from the center of the perimeter to the edge. If the radiusFraction parameter is not provided, it defaults to 1 (the edge).

Mass

body.Mass -> number

Gets the mass of body. The mass is equal to the density multiplied by the area of all colliders currently attached to this body. If the body is nullish, or body refers to an entity with no body or colliders, returns 0.

PolygonCollider

this.PolygonCollider<Id?>([shape, body], angleOffset?=, bodyOffset?, [category, parent?, 
passthroughParent?, passthroughSiblings?, isSensor?, collideWith?,
density?, friction?, restitution?, sense?, tolerance?, owner?])
delete this.PolygonCollider<Id?>

Attaches a new collider to body.

  • this (Entity): Determines the lifespan of the collider. When this despawns, the collider is removed.

  • Id: if a collider with the same this and Id already exists, it will be replaced.

  • body (Entity or Vector): The position of the collider, whether it be attached to an Entity's body or a fixed Vector position in the world. If a collider is a Vector, the collider will be placed at a fixed position and will not move in response to collision forces and will not generate collision events.

  • shape (Polygon): The shape of the collider.

  • tolerance (Number): Some shapes may need to be approximated in order to be handled by the physics engine. This value determines the maximum allowed distance between the original shape and the approximated shape. Greater tolerance allows of better performance but less accuracy. Defaults to 0.25.

  • angleOffset (Number): If set, the collider's shape will be rotated by this angle.

  • bodyOffset (Vector): If set, determines the attachment point of the collider to the body.

  • category (Categories): The categories that the collider belongs to. This determines which other colliders it will collide with. This will automatically set the Category property for this, if it is not set yet.

  • density (Number): The density of the collider, defaults to 1. Determines the mass of the collider.

  • friction (Number): Determines the amount of tangential force that opposes tangential movement in a collision. Should be a value between 0 and 1. Defaults to 0.

  • restitution (Number): Determines the amount of energy conserved in a collision. In other words, the bounciness of the collider. Should be a value between 0 and 1. Defaults to 0.

  • collideWith (Categories): This collider will only collide with other colliders belonging to these categories.

  • sense (Categories): The collider will generate collision events with these categories, but no forces will be applied. If a category is in both sense and collideWith, then sense will take precedence.

  • isSensor (Boolean): If true, the collider is a sensor. That means other collides will not generate collision events with it, and no forces will be applied when it touches other colliders.

  • parent (Entity): If set, defines a body that the collider may pass through initially when it has just spawned. This passthrough will continue until the collider stops contact with its parent. This can be used to stop a projectile immediately colliding with its parent and exploding straight away, for example.

  • passthroughParent (Boolean): If true, the collider will always pass through its parent forever, not just initially.

  • passthroughSiblings (Boolean): If true, the collider will also pass through any other colliders that are both still in their "initial passthrough" phase and have the same parent. Defaults to true.

  • owner (Entity): This will automatically set the Owner property for this, if it is not set yet.

PolygonPerimeter

this.PolygonPerimeter([shape?], bodyOffset?=, angleOffset?)
delete this.PolygonPerimeter

Assigns a polygon to be the perimeter of an entity with a Body. Perimeters are an efficient way of find a point within the area considered to be within the boundary of an entity. Perimeters are used with the LocatePerimeterPoint function to find points on or within the perimeter. They are also used with the glaze parameter of Spark to create visual effects that spread within the perimeter.

  • this (Entity): The entity to assign the perimeter to.
  • shape (Polygon): The shape of the perimeter.
  • angleOffset (Number): The angle offset of the perimeter. Defaults to 0.
  • bodyOffset (Vector): The offset of the perimeter from the body. Defaults to @(0,0).

Pos

body.Pos -> vector

Gets the current position of the body. If body is nullish or refers to an entity with no body, returns undefined.

body.Pos = value

Sets the current position of the body. If body refers to an entity that does not yet have a body, a immovable body is first created, then assigned the new position. If body is nullish, does nothing.

QueryAnyOverlapping

body.QueryAnyOverlapping<Id?>(filter?, against?=, [owner?]) -> entity

Returns one of the colliders that overlaps the given collider or position and matches the specified criteria.

  • body (Vector or Entity): A Vector position or an Entity that owns a collider to check for overlaps. Checking for a Collider rather than just a Vector position is more powerful as it checks whether the collider's entire shape overlaps, not just its center point.
  • Id: If body refers to a collider, the Id of the collider, if it has one.
  • filter (Categories): For a collider to match, both the collider's categories and it's body's Category property must overlap with the filter. Defaults to Category:All.
  • against (Flags) and owner (Entity): The alliance status between the entity and owner must overlap at least one of these alliance flags. Defaults to Alliance:All.

Only entities that have both a Collider (e.g. PolygonCollider) and a Category will be considered by this function. If an entity has multiple colliders that match, it will be returned multiple times. If no colliders overlap, returns undefined.

This function uses a cached spatial index for performance reasons. See ResetSpatialQueryIndex for more details.

QueryAnyWithinRadius

body.QueryAnyWithinRadius(radius, filter?=, against?, [owner?]) -> entity

Returns one of the colliders that is within the given radius of the given position and matches the specified criteria.

  • body (Vector or Entity): The origin point from which to search. If given an Entity, will use the position (Pos of its body. If this is nullish, returns undefined.
  • radius (Number): The radius to search within.
  • filter (Categories): For a collider to match, both the collider's categories and it's body's Category property must overlap with the filter. Defaults to Category:All.
  • against (Flags) and owner (Entity): The alliance status between the entity and owner must overlap at least one of these alliance flags. Defaults to Alliance:All.

Only entities that have both a Collider (e.g. PolygonCollider) and a Category will be considered by this function. If an entity has multiple colliders that match, it will be returned multiple times. If no colliders overlap, returns undefined.

This function uses a cached spatial index for performance reasons. See ResetSpatialQueryIndex for more details.

QueryNearest

body.QueryNearest(filter?, against?=, [owner?]) -> entity

Returns the nearest collider to the given position that matches the specified criteria.

  • body (Vector or Entity): The origin point from which to search. If given an Entity, will use the position (Pos of its body. If this is nullish, returns undefined.
  • filter (Categories): For a collider to match, both the collider's categories and it's body's Category property must overlap with the filter. Defaults to Category:All.
  • against (Flags) and owner (Entity): The alliance status between the entity and owner must overlap at least one of these alliance flags. Defaults to Alliance:All.

Only entities that have both a Collider (e.g. PolygonCollider) and a Category will be considered by this function. If an entity has multiple colliders that match, it will be returned multiple times. If no colliders overlap, returns undefined.

This function uses a cached spatial index for performance reasons. See ResetSpatialQueryIndex for more details.

QueryNearestAlongRay

body.QueryNearestAlongRay<Id?>(direction, maxDistance?=, filter?, against?, [owner?]) -> entity, distance

Searches along a ray for the nearest collider that matches the specified criteria, returning the Entity that owns the collider, and a Number representing the distance to contact.

  • body (Vector or Entity) and Id: If body is a Vector, will search from that position. If body is an Entity, will search from the position of the collider identified by body and Id. Searching using a collider can be more powerful than just a Vector position as it checks whether the collider's entire shape overlaps, not just its center point. If this is nullish, returns undefined.
  • direction (Vector): The direction to search in.
  • maxDistance (Number): The maximum distance to search.
  • filter (Categories): For a collider to match, both the collider's categories and it's body's Category property must overlap with the filter. Defaults to Category:All.
  • against (Flags) and owner (Entity): The alliance status between the entity and owner must overlap at least one of these alliance flags. Defaults to Alliance:All.

This function returns the distance to contact. This means if searching for a collider-to-collider contact along the ray, this is the minimum distance the first collider must move along the ray in order for their edges (not centroids) to touch.

Only entities that have both a Collider (e.g. PolygonCollider) and a Category will be considered by this function. If an entity has multiple colliders that match, it will be returned multiple times.

This function uses a cached spatial index for performance reasons. See ResetSpatialQueryIndex for more details.

QueryOverlapping

body.QueryOverlapping<Id?>(filter?, against?=, [owner?]) -> entityArray

Returns an array of all colliders that overlap the given collider or position and match the specified criteria.

  • body (Vector or Entity): A Vector position or an Entity that owns a collider to check for overlaps. Checking for a Collider rather than just a Vector position is more powerful as it checks whether the collider's entire shape overlaps, not just its center point.
  • Id: If body refers to a collider, the Id of the collider, if it has one.
  • filter (Categories): For a collider to match, both the collider's categories and it's body's Category property must overlap with the filter. Defaults to Category:All.
  • against (Flags) and owner (Entity): The alliance status between the entity and owner must overlap at least one of these alliance flags. Defaults to Alliance:All.

Only entities that have both a Collider (e.g. PolygonCollider) and a Category will be considered by this function. If an entity has multiple colliders that match, it will be returned multiple times. If no colliders overlap, returns an empty array.

This function uses a cached spatial index for performance reasons. See ResetSpatialQueryIndex for more details.

QueryWithinRadius

body.QueryWithinRadius(radius, filter?=, against?, [owner?]) -> entityArray

Returns an array of all colliders that are within the given radius of the given position and match the specified criteria.

  • body (Vector or Entity): The origin point from which to search. If given an Entity, will use the position (Pos of its body. If this is nullish, returns undefined.
  • radius (Number): The radius to search within.
  • filter (Categories): For a collider to match, both the collider's categories and it's body's Category property must overlap with the filter. Defaults to Category:All.
  • against (Flags) and owner (Entity): The alliance status between the entity and owner must overlap at least one of these alliance flags. Defaults to Alliance:All.

Only entities that have both a Collider (e.g. PolygonCollider) and a Category will be considered by this function. If an entity has multiple colliders that match, it will be returned multiple times. If no colliders overlap, returns an empty array.

This function uses a cached spatial index for performance reasons. See ResetSpatialQueryIndex for more details.

RecoverSpeed

body.RecoverSpeed([speed=, speedDecay?])
delete body.RecoverSpeed

Makes the speed of body recover towards speed by a certain proportion after the physics simulation phase of each tick.

  • body (Entity): The entity to modify. If nullish, this function will do nothing.
  • speed (Number): The target speed of the body.
  • speedDecay (Number): The rate at which the body's speed recovers. Should be a value between 0 and 1. Defaults to the physics.speedDecay setting in easel.toml or 0.05 if not specified.

RecoverTurnRate

body.RecoverTurnRate([turnRate=, turningDecay?])
delete body.RecoverTurnRate

Makes the turn rate of body recover by a certain proportion towards turnRate after the physics simulation phase of each tick.

  • body (Entity): The entity to modify. If nullish, this function will do nothing.
  • turnRate (Number): The target turn rate of the body.
  • turningDecay (Number): The rate at which the body's turn rate recovers. Should be a value between 0 and 1. Defaults to the physics.turningDecay setting in easel.toml or 0.5 if not specified.

ResetSpatialQueryIndex

ResetSpatialQueryIndex

Resets the cached spatial query index used by functions like QueryNearest. The spatial query index is cleared by itself at the end of each tick and after each physics simulation. Any changes to bodies or colliders after these times will not be reflected in the cached index without calling this function. Calculating the spatial query index is computationally expensive so it is recommended to only call this function only when necessary.

Speed

body.Speed -> number
body.Speed = value

Gets or sets the current speed of the body. If body is nullish or refers to an entity with no body, does nothing.

TurnRate

body.TurnRate -> number
body.TurnRate = value

Gets or sets the current turn rate of the body. If body is nullish or refers to an entity with no body, does nothing.

Velocity

body.Velocity -> vector
body.Velocity = value

Gets or sets the current velocity of the body. If body is nullish or refers to an entity with no body, does nothing.