B2.World:createBody
Available since: Gideros 2011.6
Description
Creates a rigid body given a definition. The body definition is given as an ordinary table. The fields of the body definition table are:
<ul>
<li>**type**: (number) The body type: [[[b2.STATIC_BODY`, `b2.KINEMATIC_BODY`, or `b2.DYNAMIC_BODY]]]. Note: if a dynamic body would have zero mass, the mass is set to one.</li>
<li>**position**: (table) The world position of the body (see the example below to understand how this table is set). Avoid creating bodies at the origin since this can lead to many overlapping shapes.</li>
<li>**angle**: (number) The world angle of the body in radians.</li>
<li>**linearVelocity**: (table) The linear velocity of the body's origin in world co-ordinates (see the example below to understand how this table is set).</li>
<li>**angularVelocity**: (number) The angular velocity of the body.</li>
<li>**linearDamping**: (number) Linear damping is use to reduce the linear velocity. The damping parameter can be larger than 1.0 but the damping effect becomes sensitive to the time step when the damping parameter is large.</li>
<li>**angularDamping**: (number) Angular damping is use to reduce the angular velocity. The damping parameter can be larger than 1.0 but the damping effect becomes sensitive to the time step when the damping parameter is large.</li>
<li>**allowSleep**: (boolean) Set this flag to false if this body should never fall asleep. Note that this increases CPU usage.</li>
<li>**awake**: (boolean) Is this body initially awake or sleeping?</li>
<li>**fixedRotation**: (boolean) Should this body be prevented from rotating? Useful for characters.</li>
<li>**bullet**: (boolean) Is this a fast moving body that should be prevented from tunneling through other moving bodies? Note that all bodies are prevented from tunneling through kinematic and static bodies. This setting is only considered on dynamic bodies. **Warning:** You should use this flag sparingly since it increases processing time.</li>
<li>**active**: (boolean) Does this body start out active?</li>
<li>**gravityScale**: (number) Scale the gravity applied to this body.</li>
</ul>
The unset fields gets default values.
<ul>
<li>*Warning:** This function is locked during callbacks.</li>
</ul>
(b2.Body) = b2.World:createBody(bodyDef)
Parameters
bodyDef: (table)
Return values
Returns (b2.Body) created body.
Examples
Example
local body = world:createBody{
type = b2.STATIC_BODY,
position = {x=0, y=0.5},
angle = math.pi/4,
linearVelocity = {x=0.1, y=0.2},
}