Skip to main content

PhysicsWorld

Description:

  A record that represents a physics world in the game.

Class Object: PhysicsWorld Class.

Inherits from: Node.

query

Type: Function.

Description:

  Queries the physics world for all bodies that intersect with the specified rectangle.

Signature:

query: function(self: PhysicsWorld, rect: Rect, handler: function(Body): boolean): boolean

Parameters:

ParameterTypeDescription
rectRectThe rectangle to query for bodies.
handlerfunctionA function that is called for each body found in the query.

Returns:

Return TypeDescription
booleanWhether the query was interrupted, true means interrupted, false otherwise.

Definition for handler:

  • Parameters of handler:
ParameterTypeDescription
bodyBodyThe body found in the query.
  • Returns of handler:
Return TypeDescription
booleanWhether to continue querying for more bodies, false to continue, true to stop.

raycast

Type: Function.

Description:

  Casts a ray through the physics world and finds the first body that intersects with the ray.

Signature:

raycast: function(self: PhysicsWorld, start: Vec2, stop: Vec2, closest: boolean, handler: function(Body, point: Vec2, normal: Vec2): boolean): boolean

Parameters:

ParameterTypeDescription
startVec2The starting point of the ray.
stopVec2The ending point of the ray.
closestbooleanWhether to stop ray casting upon the closest body that intersects with the ray.Set closest to true to get a faster ray casting search.
handlerfunctionA function that is called for each body found in the raycast.

Returns:

Return TypeDescription
booleanWhether the raycast was interrupted, true means interrupted, false otherwise.

Definition for handler:

  • Parameters of handler:
ParameterTypeDescription
bodyBodyThe body found in the raycast.
pointVec2The point where the ray intersects with the body.
normalVec2The normal vector at the point of intersection.
  • Returns of handler:
Return TypeDescription
booleanWhether to continue casting the ray for more bodies, returns true to stop, false otherwise.

setIterations

Type: Function.

Description:

  Sets the number of velocity and position iterations to perform in the physics world.

Signature:

setIterations: function(self: PhysicsWorld, velocityIter: integer, positionIter: integer)

Parameters:

ParameterTypeDescription
velocityIterintegerThe number of velocity iterations to perform.
positionIterintegerThe number of position iterations to perform.

setShouldContact

Type: Function.

Description:

  Sets whether two physics groups should make contact with each other or not.

Signature:

setShouldContact: function(self: PhysicsWorld, groupA: integer, groupB: integer, contact: boolean)

Parameters:

ParameterTypeDescription
groupAintegerThe first physics group.
groupBintegerThe second physics group.
contactbooleanWhether the two groups should make contact with each other.

getShouldContact

Type: Function.

Description:

  Gets whether two physics groups should make contact with each other or not.

Signature:

getShouldContact: function(self: PhysicsWorld, groupA: integer, groupB: integer): boolean

Parameters:

ParameterTypeDescription
groupAintegerThe first physics group.
groupBintegerThe second physics group.

Returns:

Return TypeDescription
booleanWhether the two groups should make contact with each other.