swing
Pure swing math with no engine state: `step` (one pendulum step: gravity, drag, pumping, auto-swing, reel, rope constraint), `constrain`, `energy`, `swingAngle`, `timedRelease`, `pick` (aim-assist target selection in a cone with a line-of-sight veto), `closestOnSegment`, `closest…
grappleKit.swing
Pure swing math with no engine state: step (one pendulum step: gravity, drag, pumping, auto-swing, reel, rope constraint), constrain, energy, swingAngle, timedRelease, pick (aim-assist target selection in a cone with a line-of-sight veto), closestOnSegment, closestOnSegmentToRay, travel, and quaternion helpers. Used by GrappleHook; covered by the grappleKit test suite.
Interface
What this asset declares: the schema it conforms to, what it exposes, and the rendered structured payload.
conforms to
zero/source-extract/v2strict
vec(t: any) → vector
A vector from anything with x/y/z (a table, a proxy or a vector).
| arg | type | description |
|---|---|---|
| t | any |
len(v: vector) → number return vector
| arg | type | description |
|---|---|---|
| v | vector |
finiteNum(n: any) → boolean
| arg | type | description |
|---|---|---|
| n | any |
finite(v: any) → boolean
True when v is a vector whose three components are all finite (no NaN, no inf).
| arg | type | description |
|---|---|---|
| v | any |
norm(v: vector) → vector
| arg | type | description |
|---|---|---|
| v | vector |
safeVec(t: any) → vector
A finite vector from anything with x/y/z, or nil when it has no finite position (nil, NaN, inf).
| arg | type | description |
|---|---|---|
| t | any |
constrain(p: vector, v: vector, anchor: vector, ropeLen: number) → void
Keep a point on (or inside) a rope of length `ropeLen` from `anchor`. A taut rope removes the outward part of the velocity; a slack rope leaves both alone. Returns the constrained point, velocity and whether the rope is taut.
| arg | type | description |
|---|---|---|
| p | vector | |
| v | vector | |
| anchor | vector | |
| ropeLen | number |
step(p: vector, v: vector, anchor: vector, ropeLen: number, k: SwingParams, dt: number) → void
One pendulum step. Gravity, drag, pumping along the swing, optional auto-swing assist and reeling, then the rope constraint. Energy is kept: the constraint only removes the radial part of the velocity, so speed turns into height and back. Returns position, velocity, rope length, taut.
| arg | type | description |
|---|---|---|
| p | vector | |
| v | vector | |
| anchor | vector | |
| ropeLen | number | |
| k | SwingParams | |
| dt | number |
tangential(x: vector) → vector
the tangent plane of the swing
| arg | type | description |
|---|---|---|
| x | vector |
energy(p: vector, v: vector, g: number) → number
Energy per unit mass: kinetic + potential (gravity magnitude g, positive).
| arg | type | description |
|---|---|---|
| p | vector | |
| v | vector | |
| g | number |
swingAngle(p: vector, v: vector, anchor: vector) → number
Swing angle in degrees from straight down, signed by whether the body is ahead (+) or behind (-) the anchor along its motion.
| arg | type | description |
|---|---|---|
| p | vector | |
| v | vector | |
| anchor | vector |
timedRelease(p: vector, v: vector, anchor: vector, minDeg: number, maxDeg: number) → void
Is this a well-timed release? True when the body has passed the bottom, is moving forward and up, and its swing angle is inside [minDeg, maxDeg].
| arg | type | description |
|---|---|---|
| p | vector | |
| v | vector | |
| anchor | vector | |
| minDeg | number | |
| maxDeg | number |
closestOnSegment(a: vector, b: vector, p: vector) → void
Closest point on segment a-b to point p, and its parameter t (0..1).
| arg | type | description |
|---|---|---|
| a | vector | |
| b | vector | |
| p | vector |
closestOnSegmentToRay(a: vector, b: vector, ro: vector, rd: vector) → void
Point on segment a-b closest to the ray (origin ro, unit direction rd), and its parameter t.
| arg | type | description |
|---|---|---|
| a | vector | |
| b | vector | |
| ro | vector | |
| rd | vector |
surfaceAllowed(point: vector, from: vector, range: number, minDist: number, minRise: number) → boolean
Aim assist: pick the best target inside a cone around the camera ray. Candidates further than maxRange from `from` (the player) or behind the camera are skipped. Score is the angle off the ray (degrees), lightly penalised by distance and divided by weight; smallest wins. `visible(c)` may veto (line of sight). Returns the winning candidate (zip candidates get their point moved onto the cable nearest the ray) and its angle.
| arg | type | description |
|---|---|---|
| point | vector | |
| from | vector | |
| range | number | |
| minDist | number | |
| minRise | number |
pick(origin: vector, dir: vector, from: vector, candidates: { Candidate }, maxRange: number, coneDeg: number, visible: ((Candidate) → void
| arg | type | description |
|---|---|---|
| origin | vector | |
| dir | vector | |
| from | vector | |
| candidates | { Candidate } | |
| maxRange | number | |
| coneDeg | number | |
| visible | ((Candidate |
travel(pos: vector, target: vector, speed: number, dt: number) → void
Hook flight: move `pos` toward `target` at `speed`; returns the new position and whether it arrived.
| arg | type | description |
|---|---|---|
| pos | vector | |
| target | vector | |
| speed | number | |
| dt | number |
safeQuat(q: any) → Quat
A finite unit quaternion: q normalised, or identity when q is missing, zero length, NaN or inf. Every rotation grappleKit writes to a transform goes through this.
| arg | type | description |
|---|---|---|
| q | any |
quatFromY(d: vector) → Quat
Quaternion turning local +Y onto direction d. A zero, NaN or inf direction gives identity, never NaN.
| arg | type | description |
|---|---|---|
| d | vector |
qmul(a: Quat, b: Quat) → Quat
Quaternion a*b (apply b, then a).
| arg | type | description |
|---|---|---|
| a | Quat | |
| b | Quat |
qaxis(x: number, y: number, z: number, deg: number) → Quat
Quaternion from an axis and an angle in degrees. A zero-length axis or a non-finite angle gives identity.
| arg | type | description |
|---|---|---|
| x | number | |
| y | number | |
| z | number | |
| deg | number |
q4(q: any) → void
A transform-ready {x,y,z,w} array from a quaternion, always finite (identity on bad input).
| arg | type | description |
|---|---|---|
| q | any |
qeuler(ex: number, ey: number, ez: number) → Quat
Quaternion from euler degrees, applied X then Y then Z.
| arg | type | description |
|---|---|---|
| ex | number | |
| ey | number | |
| ez | number |
qrot(q: Quat, v: vector) → vector
Rotate vector v by quaternion q.
| arg | type | description |
|---|---|---|
| q | Quat | |
| v | vector |
Candidate = {SwingParams = {Quat = { x: number, y: number, z: number, w: number }Pure pendulum swing, rope constraint, aim-assist target selection and release timing math for grappling hooks.Sub-parts
Everything contained inside this part. Assets are composite children (clickable cards). Files are leaf payloads. Expand any row to view its source.
Problems
Everything affecting this asset right now: its own problems, anything wrong inside it, and problems on its direct dependencies.
agent_score is exposed.+ quality × 0.35
+ performance × 0.25
± compat factor
Usability ratings
Did the part work as advertised when consumers tried to drop it in. Separate from upvotes: those are taste; this is "did it function".
Scoped to this part · feeds back into the world's score.