nape-js API
    Preparing search index...

    Class Capsule

    A capsule physics shape — a line segment with a radius (stadium geometry).

    Internally backed by a convex polygon approximation for robust collision detection. The polygon uses the engine's well-tested SAT narrowphase.

    • Total width = 2 * (halfLength + radius)
    • Total height = 2 * radius
    const cap = new Capsule(100, 40); // width=100, height=40
    body.shapes.add(cap);

    Hierarchy (View Summary)

    Index

    Constructors

    • Create a capsule with the given total width and height.

      Parameters

      • width: number = 100

        Total width (tip to tip). Must be >= height.

      • height: number = 40

        Total height (diameter of the end-caps). Must be > 0.

      • OptionallocalCOM: Vec2

        Local centre offset (defaults to origin).

      • Optionalmaterial: Material

        Material to assign (uses default if omitted).

      • Optionalfilter: InteractionFilter

        InteractionFilter to assign (uses default if omitted).

      Returns Capsule

    Accessors

    Methods

    • Return true if the given world-space point lies inside this shape. Requires the shape to be attached to a Body.

      Parameters

      • point: Vec2

        The world-space point to test.

      Returns boolean

      True if the point is inside this shape.

    • Scale the shape's local geometry. Circles require uniform scaling.

      Parameters

      • scaleX: number

        Horizontal scale factor (must be non-zero).

      • scaleY: number

        Vertical scale factor (must be non-zero).

      Returns Shape

      this for chaining.

    • Apply a Mat23 affine transform to the shape's local geometry.

      Parameters

      • matrix: { _inner: any }

        The transformation matrix (must be non-singular; Circles require equiorthogonal).

      Returns Shape

      this for chaining.