natiny.physics.capsule
Lua
natiny.physics.capsule([radius [, height]]) -> body
Creates a dynamic body with a capsule collider standing upright along Y and
centred on its origin. Requires an initialised physics world.
Parameters
| Name |
Type |
Default |
Description |
radius |
number |
0.5 |
Radius of the side and of both hemispheres, in metres; must be greater than 0 |
height |
number |
radius * 4 |
Total height end to end, hemispheres included, in metres |
Returns
| Type |
Description |
number |
Body handle |
Example
Lua
local player = natiny.physics.capsule(0.4, 1.8)
natiny.physics.set_fixed_rotation(player, true)
natiny.model.set_mesh(avatar, natiny.mesh.capsule(0.4, 1.8))
natiny.entity.set_parent(avatar, player)
Notes
- Raises an error if the body could not be created, including when
natiny.physics.init has not run or radius is not greater
than 0.
height is the whole shape, so the cylindrical side is height - 2 * radius
tall and the collider spans -height / 2 to +height / 2 along Y - the same
numbers natiny.mesh.capsule draws, so the pair line up
without an offset between them.
- A
height at or below 2 * radius becomes a sphere collider of that radius,
the same shape the mesh draws for those numbers.
- The body is dynamic; change that with
natiny.physics.set_type.
- A capsule has no corners to catch on a step, which is what makes it the
collider for a character. Pair it with
natiny.physics.set_fixed_rotation so it cannot tip
over.
- The body is an entity: place it with
natiny.entity.set_position and parent a model
to it so the model follows.