melonJS
    Preparing search index...

    Class Sphere

    A 3D sphere — { centre, radius }. Sibling of Ellipse in the geometry surface; used by Octree / adapter.querySphere as the canonical 3D region-query shape, and by user code for any sphere-vs-sphere / sphere-vs-AABB collision check under Camera3d.

    Also a BODY SHAPE. A Body carrying a Sphere is resolved by the builtin 3D narrowphase against another Sphere or a Box3d, which is what makes it the right primitive for anything that tumbles or is laid out over a curved surface: a Box3d is world-axis-aligned and cannot be oriented, so every object whose "up" points a different way needs a shape that has no "up" at all.

    import { Sphere } from "melonjs";

    const a = new Sphere(0, 0, 0, 10);
    const b = new Sphere(15, 0, 0, 10);
    a.overlaps(b); // true — surfaces touch at x = 5
    Index
    collisionMask?: number
    collisionType?: number

    Optional per-shape collision settings, honoured by Body#addShape and defaulted there. Declared rather than initialized: the body writes them when the shape joins it, so a class field here would emit an undefined own property on every shape ever built. See addShape for the table of defaults and what each one does.

    Body#addShape

    isActive?: boolean

    false takes this shape out of collision without removing it

    isTrigger?: boolean

    true reports contacts but skips the position correction

    Centre coordinates of the sphere (Y-down, +Z forward — Camera3d convention).

    radius: number

    Sphere radius. Negative values are treated like their absolute value in Sphere.overlaps / Sphere.contains.

    type: string = "Sphere"

    Shape tag, as the narrowphase's pair table keys on. That table is a string concat of the two shapes' types and a missing entry is a hard failure rather than a missed collision, so this has to match the entries registered in the detector exactly.

    • Smallest AABB3d containing this sphere. The same instance every time, refreshed from the current centre and radius on each call, so it is never stale: as a body shape a sphere gets moved by whoever owns it — directly through pos, not only through Sphere.setShape — and a cache that only refreshed on setShape reported the position the sphere was first asked about for the rest of its life. Callers must not hold the instance across a move and expect the old values.

      Returns AABB3d