Confiner

Keeps the camera inside a box or a sphere.

Keeps the camera inside a box or a sphere, like a room it must not leave. Inside, nothing changes. When the Body puts the camera outside, it moves to the closest point on the edge. With slowingDistance, it eases into the edge instead: within that distance of it, the camera moves less the farther the Body pushes it, so it slides up to the wall without a bump.

It runs right after the Body, before the Aim, so the Aim looks from where the camera ends up. A Body with damping stays at the edge while its target is outside, and moves back in once the target returns.

Settings

SettingDescriptionDefault
boundsThe box, [minX, minY, minZ, maxX, maxY, maxZ], or the sphere, { center, radius }. In three.js and React also a Box3 or a Sphere, read every frame. null or an empty box or sphere confines nothing.
slowingDistanceWidth of the zone inside the edge where the camera slows down, in world units. 0 stops it at the edge.0

Usage

import { ConfinerExtension } from '@pmndrs/klipp';

camera.addExtension(new ConfinerExtension([-10, 0.5, -10, 10, 6, 10], { slowingDistance: 1 }));