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
    • 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

    • get sensorEnabled(): boolean

      If true, this shape acts as a sensor (no physical response, only callbacks).

      Cannot be changed during space.step(), which includes PreListener handlers (they run mid-step). Record the desired state in the handler and apply it after step() returns. Body / interaction / constraint listener callbacks are delivered after the step and may change it directly.

      Returns boolean

    • set sensorEnabled(value: boolean): void

      Parameters

      • value: boolean

      Returns void

    • 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.