natiny_physics_capsule

C
NatinyBody natiny_physics_capsule(float radius, float height);

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 Description
radius float Radius of the side and of both hemispheres, in metres; must be greater than 0
height float Total height end to end, hemispheres included, in metres

Returns

Type Description
NatinyBody Body handle, or 0 on failure

Example

C
NatinyBody player = natiny_physics_capsule(0.4f, 1.8f);
natiny_physics_set_fixed_rotation(player, true);
natiny_model_set_mesh(avatar, natiny_mesh_capsule(0.4f, 1.8f, 32, 8));
natiny_entity_set_parent(avatar, player);

Notes

  • Returns 0 when natiny_physics_init has not run, when radius is not greater than 0, or when the shape could not be created; nothing is left behind in that case.
  • 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.