Module body
A Body is the representation of an Entity in physics space.
As such, it is only relevant in Scenes driven by physics engines.
The Body is used to represent the Entity in the physical space.
The Sprite represents it in the graphical space. The Body
dimensions, rotation, and position determine how the Sprite is drawn.
If you need to set a collision area that is smaller than the Sprite's
cell size, use set_hit_box.
Body extends BoundObject
Properties
| angle | The current rotation of the Body in radians |
| can_rotate | (bool) Whether the Body can rotate on its own. |
| elasticity | Elasticity factor, on a scale of 0.0 (Not bouncy) to 1.0 (Perfectly bouncy). |
| entity | (read only) The Entity the Body is attached to. |
| force | The current amount of force being applied to Body in Newtons. |
| friction | Coefficient of friction, on a scale of 0.0 (Smooth) to 1.0 (Sticky). |
| is_rogue | (bool) If true, then Body is not modified by the physics
solver. |
| is_static | (bool) If true, then Body does not collide with other
objects. |
| mass | Mass in kg |
| pos | An {x, y} vector of the Body's center in the physics space (in
meters). |
| velo | An {x, y} vector of the Body's velocity (in meters per
second). |
| collision_layers | Set the collision bit-plane of the Body. |
| sensors | The Collection of the Body's Sensors |
Class Methods
| Body:new (proto, width, height, mass, can_rotate) | Create a new Body |
Instance Methods
| body:apply_force (force, offset) | Apply a force on the next solve. |
| body:set_hit_box (width, height, offset) | Set the Body's collision box in relation to the Body's dimensions. |
Properties
Properties. Significant fields on an instance.- angle
-
The current rotation of the
Bodyin radians - can_rotate
-
(bool) Whether the
Bodycan rotate on its own. - elasticity
- Elasticity factor, on a scale of 0.0 (Not bouncy) to 1.0 (Perfectly bouncy).
- entity
-
(read only) The Entity the
Bodyis attached to. - force
-
The current amount of force being applied to
Bodyin Newtons. - friction
- Coefficient of friction, on a scale of 0.0 (Smooth) to 1.0 (Sticky).
- is_rogue
-
(bool) If
true, thenBodyis not modified by the physics solver.This could be useful for something like a gate or moving platform.
- is_static
-
(bool) If
true, thenBodydoes not collide with other objects. Sensors attached toBodywill still work.This could be useful for something like a door or switch.
- mass
- Mass in kg
- pos
-
An
{x, y}vector of theBody's center in the physics space (in meters).Warning: You must set the property explicitly for changes to take apply. Like this:
body.pos = {10, 11}Not this:
body.pos[1] = 10 - velo
-
An
{x, y}vector of theBody's velocity (in meters per second).Warning: You must set the property explicitly for changes to take apply. Like this:
body.velo = {5, 0}Not this:
body.velo[1] = 5 - collision_layers
-
Set the collision bit-plane of the
Body.Bodies only collide if they are in the same bit-planes. i.e. (a.collision_layers & b.collision_layers) != 0.
By default, a
Bodyoccupies all bit-planes. - sensors
- The Collection of the Body's Sensors
Class Methods
Class Methods. Must be called onClass, with a capital leading character.
e.g. Class:method("foo")
- Body:new (proto, width, height, mass, can_rotate)
-
Create a new
BodyParameters:
- proto
string
The
Bodyprototype. Currently, the only valid - width number The width of the body in meters.
- height number The height of the body in meters.
- mass number The mass of the body in kg.
- can_rotate
boolean
Whether the
Bodycan rotate or not option is"chipmunk"
Returns:
-
Body
- proto
string
The
Instance Methods
Instance Methods. Must be called on an instance ofClass.
e.g. instance:method("foo")
- body:apply_force (force, offset)
-
Apply a force on the next solve.
Parameters:
- force
table
An
{x, y}vector of the force in Newtons (kg * m / s ^ 2). - offset
table
An
{x, y}vector of the offset from center the force is applied to (in respect to rotation).
Returns:
-
nil
Usage:
body:apply_force({100, 0}, {0, 0}) -- Push right - force
table
An
- body:set_hit_box (width, height, offset)
-
Set the
Body's collision box in relation to theBody's dimensions.Parameters:
- width
number
The width of the hitbox, as a coefficient of the
Body's width. - height
number
The height of the hitbox, as a coefficient of the
Body's height. - offset
table
An
{x, y}vector of the hitbox center in relation to theBody's center in meters.
Returns:
-
nil
Usage:
body:set_hit_box(0.5, 0.5, {0, 10}) -- A hitbox half the size
- width
number
The width of the hitbox, as a coefficient of the