nape-js API
    Preparing search index...

    Class Capsule

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

    Geometrically equivalent to a rectangle with two semicircular end-caps. The spine runs along the local X-axis through localCOM.

    • 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

    • get angDrag(): number

      Angular drag coefficient for this shape.

      Returns number

    • get area(): number

      Cross-sectional area of this shape.

      Returns number

    • get castBody(): any

      Cast to Body — returns the Body wrapper if this is a Body, else null.

      Returns any

    • get castCapsule(): Shape | null

      Cast to Capsule, or null if this is not a capsule.

      Returns Shape | null

    • get castCircle(): Shape | null

      Cast to Circle, or null if this is not a circle.

      Returns Shape | null

    • get castCompound(): any

      Cast to Compound — returns the Compound wrapper if this is a Compound, else null.

      Returns any

    • get castPolygon(): Shape | null

      Cast to Polygon, or null if this is not a polygon.

      Returns Shape | null

    • get castShape(): any

      Cast to Shape — returns the Shape wrapper if this is a Shape, else null.

      Returns any

    • get fluidEnabled(): boolean

      If true, this shape participates in fluid interaction.

      Returns boolean

    • set fluidEnabled(value: boolean): void

      Parameters

      • value: boolean

      Returns void

    • get halfLength(): number

      Half the spine length. Total width = 2 * (halfLength + radius).

      Returns number

    • set halfLength(value: number): void

      Parameters

      • value: number

      Returns void

    • get height(): number

      Total height of the capsule (diameter of end-caps).

      Returns number

    • get id(): number

      Unique numeric identifier for this interactor.

      Returns number

    • get inertia(): number

      Contribution to moment of inertia (about local centroid, unit density).

      Returns number

    • get sensorEnabled(): boolean

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

      Returns boolean

    • set sensorEnabled(value: boolean): void

      Parameters

      • value: boolean

      Returns void

    • get userData(): Record<string, unknown>

      User-defined data storage object.

      Returns Record<string, unknown>

    • get worldCOM(): Vec2

      World-space centre of mass of this shape (read-only, lazy-computed).

      Returns Vec2

    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.

    • Create a deep copy of this shape with the same type, geometry, material, and filter.

      Returns Shape

      A new Shape instance independent of this one.

    • Rotate the shape's local vertices by angle radians.

      Parameters

      • angle: number

        Rotation in radians.

      Returns Shape

      this for chaining.

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