melonJS
    Preparing search index...

    Class Capsule3d

    A capsule standing upright: a vertical cylinder with a half-sphere on each end, usable as a Body collision shape. The shape for a character in a 3D world: its rounded bottom slides up slopes and steps instead of catching on every edge, as a box would.

    Like Box3d and Sphere, pos is the center, and the convention is the engine's 3D one (see Camera3d): Y-down, +Z forward. It stands along Y; a physics engine that turns bodies turns it with its body.

    A 3D physics adapter (@melonjs/rapier3d-adapter) builds it exactly. The built-in physics approximates it by its bounding Box3d, and the 2D adapters refuse it.

    // a character 180 units tall, 30 across, centered on its own position
    hero.bodyDef = { type: "dynamic", shapes: [new Capsule3d(0, 0, 0, 15, 180)] };
    Index
    • Parameters

      • x: number = 0

        center on the horizontal axis

      • y: number = 0

        center on the vertical axis

      • z: number = 0

        center on the depth axis

      • radius: number = 0

        the radius of the cylinder and its ends

      • height: number = 0

        the total height, ends included

      Returns Capsule3d

    collisionMask?: number
    collisionType?: number

    Optional per-shape collision settings (see Body#addShape).

    height: number

    the total height, rounded ends included; never less than 2 × radius

    isActive?: boolean

    false takes this shape out of collision without removing it

    isTrigger?: boolean

    true reports contacts but skips the position correction

    the center of the capsule, as an offset from the owning body's position

    radius: number

    the radius of the cylinder and of its two rounded ends

    type: string = "Capsule3d"

    the shape type (used internally)

    "Capsule3d"
    
    • get halfSegment(): number

      half the length of the straight part between the two rounded ends: 0 for a capsule that is a sphere, and never less, whatever radius and height were set to since Capsule3d#setShape. What Rapier calls the capsule's half height.

      Returns number

    • true if this capsule contains the given point

      Parameters

      • x: number | Vector3d

        point x, or a vector carrying the whole point

      • Optionaly: number = 0

        point y

      • Optionalz: number = 0

        point z

      Returns boolean

    • set a new position and size

      Parameters

      • x: number

        center on the horizontal axis

      • y: number

        center on the vertical axis

      • z: number

        center on the depth axis

      • radius: number

        the radius of the cylinder and its ends

      • height: number

        the total height, ends included

      Returns Capsule3d

      this capsule, for chaining