Category:Physics Engine/Bodies
A body holds the physical properties (mass, position, rotation, velocity, etc.) of an object. It does not have a shape until you attach one (or more) to it. Its type is TI.cpBody.
Body
body = physics.Body(mass, inertia)
Parameter | Type | Description |
---|---|---|
mass | in number | Mass of the body |
inertia | in number | The inertia of the body |
body | out physics.Body | A new Body with the supplied mass and inertia |
Returns a new Body with the given mass and moment of inertia.
Use the provided helper functions to compute the moment of inertia.
Introduced in platform.apiLevel = '2.0'
activate
self = physics.Body:activate()
Parameter | Type | Description |
---|---|---|
self | in physics.Body | The input Body |
self | out physics.Body | The input Body is returned as the output |
Activates a sleeping body.
See [http://files.slembcke.net/chipmunk/release/Chipmunk-5.x/Chipmunk-5.3.4-Docs/] for an explanation of this routine.
INFO |
Introduced in platform.apiLevel = '2.0'
angle
angle = physics.Body:angle()
Parameter | Type | Description |
---|---|---|
self | in physics.Body | The input Body |
angle | out number | The angle of the Body in radians |
Returns the angle in radians of the orientation of the body.
Introduced in platform.apiLevel = '2.0'
angVel
avel = physics.Body:angVel()
Parameter | Type | Description |
---|---|---|
self | in physics.Body | The input Body |
avel | out number | The angular velocity of the Body in radians per unit time |
Returns the angular velocity of the body in radians per unit time.
Introduced in platform.apiLevel = '2.0'
applyForce
self = physics.Body:applyForce(forceVect, rOffset)
Parameter | Type | Description |
---|---|---|
self | in physics.Body | The input Body |
forceVect | in physics.Vect | A force vector |
rOffset | in physics.Vect | Vector offset of the force relative to the Body |
self | out physics.Body | The input Body is returned as the output |
Apply force vector on self at a relative offset from the center of gravity.
Introducted in platform.apiLevel = '2.0'
applyImpulse
self = physics.Body:applyImpulse(impulseVect, rOffset)
Parameter | Type | Description |
---|---|---|
self | in physics.Body | The input Body |
impulseVect | in physics.Vect | Impulse force on the Body |
rOffset | in physics.Vect | Vector offset of the force relative to the Body |
self | out physics.Body | The input Body is returned as the output |
Apply the impulse vector to self at a relative offset from the center of gravity.
Introducted in platform.apiLevel = '2.0'
data
obj = physics.Body:data()
Parameter | Type | Description |
---|---|---|
self | in physics.Body | The input Body |
obj | out Lua object | An object previously set on the Body by the programmer |
Returns the contents of the programmer data field of the Body.
Introducted in platform.apiLevel = '2.0'
force
fvec = physics.Body:force()
Parameter | Type | Description |
---|---|---|
self | in physics.Body | The input Body |
fvec | out physics.Vect | The force vector on the Body |
Returns the force vector on the body.
Introduced in platform.apiLevel = '2.0'
isRogue
bool = physics.Body:isRogue()
Parameter | Type | Description |
---|---|---|
self | in physics.Body | The input Body |
bool | out boolean | True if the Body is a rogue Body |
Returns true if the Body is a rogue Body, never having been added to the simulation Space.
See [http://files.slembcke.net/chipmunk/release/Chipmunk-5.x/Chipmunk-5.3.4-Docs/] for an explanation of rogue bodies.
INFO |
Introduced in platform.apiLevel = '2.0'
isSleeping
bool = physics.Body:isSleeping()
Parameter | Type | Description |
---|---|---|
self | in physics.Body | The input Body |
bool | out boolean | True if the Body is sleeping |
Returns true if the body is sleeping.
See [http://files.slembcke.net/chipmunk/release/Chipmunk-5.x/Chipmunk-5.3.4-Docs/] for an explanation of sleeping bodies.
INFO |
Introduced in platform.apiLevel = '2.0'
local2World
wvec = physics.Body:local2World(lvec)
Parameter | Type | Description |
---|---|---|
self | in physics.Body | The input Body |
lvec | in physics.Vect | A vector relative to the position of the Body |
wvec | out physics.Vect | A vector in world coordinates |
Converts lvec from body-relative coordinates to world coordinates. Returns the converted vector.
Introduced in platform.apiLevel = '2.0'
kineticEnergy
ke = physics.Body:kineticEnergy()
Parameter | Type | Description |
---|---|---|
self | in physics.Body | The input Body |
ke | out number | The total kinetic energy of the Body |
Returns the kinetic energy of the body.
Introduced in platform.apiLevel = '2.0'
mass
m = physics.Body:mass()
Parameter | Type | Description |
---|---|---|
self | in physics.Body | The input Body |
m | out number | The mass of the Body |
Returns the mass of the body.
Introduced in platform.apiLevel = '2.0'
moment
m = physics.Body:moment()
Parameter | Type | Description |
---|---|---|
self | in physics.Body | The input Body |
m | out number | The moment of inertia of the Body |
Returns the moment of inertia of the body.
Introduced in platform.apiLevel = '2.0'
pos
p = physics.Body:pos()
Parameter | Type | Description |
---|---|---|
self | in physics.Body | The input Body |
p | out physics.Vect | The position of the Body |
Returns the vector position of the body.
Introduced in platform.apiLevel = '2.0'
resetForces
self = physics.Body:resetForces()
Parameter | Type | Description |
---|---|---|
self | in physics.Body | The input Body |
self | out physics.Body | The input Body is returned as the output |
Zero both the force and torque accumulated on self.
Introducted in platform.apiLevel = '2.0'
rot
rvec = physics.Body:rot()
Parameter | Type | Description |
---|---|---|
self | in physics.Body | The input Body |
rvec | out physics.Vect | The unit vector orientation of the Body |
Returns the vector orientation of the body. This is a unit vector cached from the last calculated angle of the Body.
Introduced in platform.apiLevel = '2.0'
setAngle
self = physics.Body:setAngle(angle)
Parameter | Type | Description |
---|---|---|
self | in physics.Body | The input Body |
angle | in number | The angle of rotation in radians of the Body |
self | out physics.Body | The input Body is returned as the output |
Updates the angle of rotation in radians of the body.
Returns the Body.
Introduced in platform.apiLevel = '2.0'
setAngVel
self = physics.Body:setAngVel(vel)
Parameter | Type | Description |
---|---|---|
self | in physics.Body | The input Body |
vel | in number | The angular velocity in radians per unit time of the Body |
self | out physics.Body | The input Body is returned as the output |
Updates the angular velocity of the body. The angular velocity is in radians per unit time.
Returns the Body.
Introduced in platform.apiLevel = '2.0'
setData
self = physics.Body:setData(value)
Parameter | Type | Description |
---|---|---|
self | in physics.Body | The input Body |
value | in object | A programmer-supplied Lua object |
self | out physics.Body | The input Body is returned as the output |
Sets the programmer data field of the Body. The programmer can store any Lua object in this field. This is a handy place to store a reference to a simulation object.
Returns the Body.
Introduced in platform.apiLevel = '2.0'
setForce
self = physics.Body:setForce(vector)
Parameter | Type | Description |
---|---|---|
self | in physics.Body | The input Body |
vector | in physics.Vect | The vector of force on the Body |
self | out physics.Body | The input Body is returned as the output |
Updates the force vector on the body.
Returns the Body.
Introduced in platform.apiLevel = '2.0'
setMass
self = physics.Body:setMass(mass)
Parameter | Type | Description |
---|---|---|
self | in physics.Body | The input Body |
mass | in number | The mass of the Body |
self | out physics.Body | The input Body is returned as the output |
Updates the mass of the body.
Returns the Body.
Introduced in platform.apiLevel = '2.0'
setMoment
self = physics.Body:setMoment(moment)
Parameter | Type | Description |
---|---|---|
self | in physics.Body | The input Body |
moment | in number | The moment of inertia of the Body |
self | out physics.Body | The input Body is returned as the output |
Updates the moment of inertia of the body.
Use the provided helper functions to compute the moment of inertia.
Returns the Body.
Introduced in platform.apiLevel = '2.0'
setPos
self = physics.Body:setPos(vector)
Parameter | Type | Description |
---|---|---|
self | in physics.Body | The input Body |
vector | in physics.Vect | The position of the Body |
self | out physics.Body | The input Body is returned as the output |
Updates the position of the body.
Returns the Body.
Introduced in platform.apiLevel = '2.0'
setPositionFunc
self = physics.Body:setPositionFunc(func)
Parameter | Type | Description |
---|---|---|
self | in physics.Body | The input Body |
func | in function(body, dt) | A callback function that updates the position of the Body on each time step |
self | out physics.Body | The input Body is returned as the output |
Sets the position function of the body. The position function must be a function that accepts a Body and a time step value and at some point calls body:updatePosition to update the position of the body.
Returns the Body.
-- TODO This is a lame example function samplePositionFunc(body, dt) -- What goes here? body:updatePosition(dt) end body:setPositionFunc(samplePositionFunc)
TIP: Example |
Introduced in platform.apiLevel = '2.0'
setTorque
self = physics.Body:setTorque(torque)
Parameter | Type | Description |
---|---|---|
self | in physics.Body | The input Body |
torque | in number | The torque of the Body |
self | out physics.Body | The input Body is returned as the output |
Updates the torque on the body. Torque is a numeric magnitude.
Returns the Body.
Introduced in platform.apiLevel = '2.0'
setVel
self = physics.Body:setVel(vector)
Parameter | Type | Description |
---|---|---|
self | in physics.Body | The input Body |
vector | in physics.Vect | The velocity vector of the Body |
self | out physics.Body | The input Body is returned as the output |
Updates the velocity of the body.
Returns the Body.
Introduced in platform.apiLevel = '2.0'
setVelocityFunc
self = physics.Body:setVelocityFunc(func)
Parameter | Type | Description |
---|---|---|
self | in physics.Body | The input Body |
func | in function(body, grav, damping, dt) | A callback function that updates the velocity of the Body on each time step |
self | out physics.Body | The input Body is returned as the output |
Sets the velocity function of the body. The velocity function must be a function that accepts a Body, a gravity vector, a numeric damping factor, and a time step value. The function should call body:updateVelocity to adjust the velocity of the body.
Returns the Body.
function sampleVelocityFunc(body, gravity, damping, dt) local pos = body:pos() local sqdist = pos:lengthsq() local g = pos:mult(-GravityStrength / (sqdist * math.sqrt(sqdist))) body:updateVelocity(g, damping, dt) end body:setVelocityFunc(sampleVelocityFunc)
TIP: Example |
Introduced in platform.apiLevel = '2.0'
setVLimit
self = physics.Body:setVLimit(limit)
Parameter | Type | Description |
---|---|---|
self | in physics.Body | The input Body |
limit | in number | The maximum speed of the Body |
self | out physics.Body | The input Body is returned as the output |
Sets the limit for the maximum speed of the body.
Returns the Body.
Introduced in platform.apiLevel = '2.0'
setWLimit
self = physics.Body:setWLimit(limit)
Parameter | Type | Description |
---|---|---|
self | in physics.Body | The input Body |
limit | in number | The maximum angular velocity of the Body |
self | out physics.Body | The input Body is returned as the output |
Updates the limit of the angular velocity of the body. Angular velocity is in radians per unit time.
Returns the Body.
Introduced in platform.apiLevel = '2.0'
sleep
self = physics.Body:sleep()
Parameter | Type | Description |
---|---|---|
self | in physics.Body | The input Body |
self | out physics.Body | The input Body is returned as the output |
Puts the body to sleep.
See [http://files.slembcke.net/chipmunk/release/Chipmunk-5.x/Chipmunk-5.3.4-Docs/] for an explanation of sleeping bodies.
INFO |
The body must be added to a Space before it can be put to sleep.
Calling this function within a query or callback is not allowed.
NOTE: NOTES |
Introduced in platform.apiLevel = '2.0'
sleepWithGroup
self = physics.Body:sleepWithGroup( [group] )
Parameter | Type | Description |
---|---|---|
self | in physics.Body | The input Body |
group | in physics.Body | A sleeping body. If this parameter is not supplied, a new group is created |
self | out physics.Body | The input Body is returned as the output |
Puts the Body to sleep and adds it to a group of other sleeping bodies.
See [http://files.slembcke.net/chipmunk/release/Chipmunk-5.x/Chipmunk-5.3.4-Docs/] for an explanation of this routine.
INFO |
The body must be added to a Space before it can be put to sleep.
Calling this function within a query or callback is not allowed.
NOTE: NOTE |
This routine will raise an exception if group is not sleeping.
Introduced in platform.apiLevel = '2.0'
torque
t = physics.Body:torque()
Parameter | Type | Description |
---|---|---|
self | in physics.Body | The input Body |
torque | out number | The torque on the Body |
Returns the torque on the body.
Introduced in platform.apiLevel = '2.0'
updatePosition
physics.Body:updatePosition(dt)
Parameter | Type | Description |
---|---|---|
self | in physics.Body | The input Body |
dt | in number | The time interval in seconds |
Updates the position of the body using Euler integration.
See [http://files.slembcke.net/chipmunk/release/Chipmunk-5.x/Chipmunk-5.3.4-Docs/] for an explanation of this routine.
INFO |
Introduced in platform.apiLevel = '2.0'
updateVelocity
physics.Body:updateVelocity(grav, damp, dt)
Parameter | Type | Description |
---|---|---|
self | in physics.Body | The input Body |
grav | in physics.Vect | The force of gravity |
damp | in physics.Vect | The damping factor |
dt | in physics.Vect | The time interval in seconds |
Updates the velocity of the body using Euler integration.
See [http://files.slembcke.net/chipmunk/release/Chipmunk-5.x/Chipmunk-5.3.4-Docs/] for an explanation of this routine.
INFO |
Introduced in platform.apiLevel = '2.0'
vel
vvel = physics.Body:vel()
Parameter | Type | Description |
---|---|---|
self | in physics.Body | The input Body |
vvel | out physics.Vect | The velocity of the Body |
Returns the vector velocity of the body.
Introduced in platform.apiLevel = '2.0'
vLimit
vmax = physics.Body:vLimit()
Parameter | Type | Description |
---|---|---|
self | in physics.Body | The input Body |
vmax | out number | The maximum speed of the Body |
Returns the speed limit of the body.
Introduced in platform.apiLevel = '2.0'
wLimit
wmax = physics.Body:wLimit()
Parameter | Type | Description |
---|---|---|
self | in physics.Body | The input Body |
wmax | out number | The maximum angular velocity of the Body in radians per unit time |
Returns the angular velocity limit of the body. The angular velocity is in radians per unit time.
Introduced in platform.apiLevel = '2.0'
world2Local
lvec = physics.Body:world2Local(wvec)
Parameter | Type | Description |
---|---|---|
self | in physics.Body | The input Body |
wvec | in physics.Vect | A vector in world coordinates |
lvec | out physics.Vect | A vector relative to the position of the Body |
Converts wvec from world coordinates to body-relative coordinates. Returns the converted vector.
Introduced in platform.apiLevel = '2.0'
This category currently contains no pages or media.