Small World Engine API Reference - v0.76.20
    Preparing search index...

    Class Collision

    Static class for collision detection and resolution.

    Index
    • Resolves collision between two axis-aligned boxes, returning a correction vector.

      Parameters

      • b1: BoundingBox

        The first box.

      • b2: BoundingBox

        The second box.

      • result: Vector3D

        Vector to store the correction (points from b2 to b1, along the axis of least penetration).

      Returns boolean

      True if collision was resolved.

    • Resolves collision between an axis-aligned box and an oriented bounding box, returning a correction vector.

      Parameters

      • b: BoundingBox

        The box.

      • o: OBB

        The OBB.

      • result: Vector3D

        Vector to store the correction (points from o to b).

      Returns boolean

      True if collision was resolved.

    • Resolves collision between two OBBs via the Separating Axis Theorem, returning the minimum-translation-vector correction.

      Parameters

      • a: OBB

        The first OBB.

      • b: OBB

        The second OBB.

      • result: Vector3D

        Vector to store the correction (points from b to a, along the axis of least penetration).

      Returns boolean

      True if collision was resolved.

    • Resolves collision between a sphere and an OBB, returning a correction vector.

      Parameters

      • s: BoundingSphere

        The sphere.

      • o: OBB

        The OBB.

      • result: Vector3D

        Vector to store the correction (points from the OBB towards the sphere).

      Returns boolean

      True if collision was resolved.

    • Sweeps a moving sphere against a static AABB for CCD. Approximates the swept volume as the box expanded by the sphere's radius on every axis (a cheap, standard approximation -- the true Minkowski sum would round the box's edges/corners, which this cheap version doesn't).

      Parameters

      • origin: Vector3D

        The moving sphere's center at the start of this step.

      • delta: Vector3D

        The moving sphere's displacement over this step (not normalized).

      • radius: number

        The moving sphere's radius.

      • b: BoundingBox

        The static box to sweep against.

      Returns number

      The time-of-impact as a fraction of delta in [0, 1], or -1 if no impact.

    • Sweeps a moving sphere against a static OBB for CCD, by transforming the sweep into the OBB's local space (where it becomes an axis-aligned sphere-vs-box sweep, same approach as sweepSphereBox).

      Parameters

      • origin: Vector3D

        The moving sphere's center at the start of this step.

      • delta: Vector3D

        The moving sphere's displacement over this step (not normalized).

      • radius: number

        The moving sphere's radius.

      • o: OBB

        The static OBB to sweep against.

      Returns number

      The time-of-impact as a fraction of delta in [0, 1], or -1 if no impact.

    • Sweeps a moving sphere against a static sphere, used for Continuous Collision Detection (CCD) of fast-moving bodies that could otherwise tunnel through thin/small geometry in a single discrete step.

      Parameters

      • origin: Vector3D

        The moving sphere's center at the start of this step.

      • delta: Vector3D

        The moving sphere's displacement over this step (NOT normalized -- its length matters, since the returned time-of-impact is a fraction of this vector).

      • radius: number

        The moving sphere's radius.

      • s: BoundingSphere

        The static sphere to sweep against.

      Returns number

      The time-of-impact as a fraction of delta in [0, 1], or -1 if no impact occurs during this sweep (including if the two spheres already overlap at origin, since that's a pre-existing overlap the discrete resolver already handles, not a new tunneling event).