Camera limits
Skill ferret-camera-limits · download all skills · SKILL.md
When to use#
A free or orbiting camera must not fly into ships, people, walls, the ground or the sea, must stay in the map, or must keep a distance from things.
The model#
CameraLimits holds limits (keepOff, keepIn, floor, ceiling, custom) over shapes (sphere, capsule, box with yaw, cylinder). resolve(from, to) turns a wished move into an allowed one: sliding along a boundary, in steps of maxStep. A limit's intrusion is stay (the world may come to the camera; the camera may only move away) or push (the camera is moved out). jump(p) lands a cut or a teleport on the nearest allowed place.
Steps#
- List the limits; for many moving things give
keepOffa function(p, reach) => shapesthat returns only what is near p. - Put each shape where the thing really is (its own ground height, its heading, its size).
- Either
attachCameraLimits(scene, camera, limits), or calllimits.resolve(pos, pos + move)in your own camera code; route every source of movement (keys, mouse, VR sticks, scripts) through it. - Cuts and teleports:
jump(p).
Check afterwards#
Fly at each kind of thing with the real keys at the highest speed and measure the gap to the thing after every frame (not every 100 ms): it must not go under the distance. Unit-test resolve on the shapes without a scene.
What usually goes wrong#
- A shape at a fixed height while the thing stands on a dune: the camera passes over the shape into the thing.
- Code that writes the camera position after the limits ran: that move is never checked.
maxSteplarger than the thin things: a fast camera crosses them.- Measuring with a test whose camera never moved: check that it got near (the gap fell) before checking the minimum.
Files#
reference/camera-limits.md— Where a camera may go: keep off things by a distance, stay in a region, over a floor and under a ceiling, or by a rule of your own; moves slide along the limits, fast moves cannot jump through, and the world may come to the camera without shoving it.reference/api-view.md— every export of@ferret/viewwith signature and doc commentreference/commands.md— 3 commands of these packages with their arguments