Physics · function
cylinderShape
A cylinder: a segment along y, grown by a disc rather than by a ball.
Explained in Your first game, Rigid bodies.
function cylinderShape(radius: number, halfHeight: number): ConvexShapeimport { cylinderShape } from '@driftengine/physics';Parameters
| Parameter | Type | Description |
|---|---|---|
radius | number | |
halfHeight | number |
In depth
The one shape a point cloud plus a rounding radius cannot express, and the reason it needed
a second kind of rounding rather than a second shape type. radius grows a shape uniformly, so
applying it to a segment gives a capsule; sideRadius grows it only perpendicular to that
segment, which gives two flat cap discs, a curved side, and a sharp rim between them. That rim
is the whole difference, and it is what a wheel rolls on.
What this replaces is an n-gon prism with a measured floor. prismRoll.test.ts had the
numbers: hullShape refuses more than 64 points, a prism spends two a side, so thirty-two sides
was the wall, and a thirty-two-sided wheel of radius 1 rolling at 6 m/s bobbed 16 mm — which
no side count could reduce. A cylinder's support along any direction perpendicular to its axis
is exactly sideRadius, at every angle, so the same wheel bobs by nothing at all. The same test
file now measures both and compares them.
It stands along y for capsuleShape's reason: a rotation nobody has to apply is a rotation
nobody gets wrong. A wheel wants its axis across the vehicle, and the body carries a quaternion
for exactly that. A static collider baked into world space carries its axis in its own two
points, so nothing stores a direction that could disagree with them.
halfHeight must be positive, unlike capsuleShape, whose zero case degenerates into a
sphere and is right. A cylinder of zero height is a disc: a shape with no interior, whose mass
properties are zero and whose contact normal is undefined on its rim. Refused rather than
silently produced.