Rides a node along a spline path by arc-length progress, optionally turning it to face the direction of travel — the way to move an object along an arbitrary 2D or 3D curve.
JavaScript API:
AlignToSplineConstraint
This is the path-following member of the Constraint family: like every
constraint it drives its constrained
target — here the target's position, and its orientation when tangential — by
recomputing from live scene state each frame, so the target keeps riding the
curve even as the curve itself moves or morphs.
Key attributes. progress is arc-length position along the spline: 0 = the
start, 1 = the end. A fractional value outside [0, 1] wraps by its fractional
part (negative values count back from the end), while whole numbers 1, 2, 3…
all rest at the end — so animating it 0 → 1 sweeps the whole path once. spline
names the AbstractSpline to follow by
#id — any sk-spline, sk-path-spline, or sk-points-spline.
tangential turns the target so its +Y axis faces along the direction of
travel (the path tangent); leave it off to keep the target's own orientation and
only move its position. up-vector disambiguates roll about the tangent when
tangential is on and usually needs no override (it defaults to world +Y).
Related. The spline it follows is any member of the AbstractSpline
family. Sibling constraints in the Constraint family include
sk-orbit-constraint (revolve around a pivot) and
sk-target-at-constraint (aim an axis at a node); the GPU-parallel
PointConstraint applies path-like displacement to many cloned points.
Serve these docs to run the live example.
WebGPU needs a secure context — open this page via grunt serve
rather than double-clicking the file. The Markup tab works from disk.
<!-- Flies a moving X/Y/Z coordinate frame along a genuinely 3D spline — the
closed Catmull-Rom curve through a cube's corners, not a flat loop SVG
could already do. `progress` (animated 0→1) sweeps the frame along the
path; `tangential` turns the whole frame so its +Y (the green up-arrow)
tracks the tangent, banking through the curve. Read POSITION from the
centre sphere and ORIENTATION from the three axis arrows. -->
<sk-scene>
<sk-directional-light p="52deg" h="23deg" intensity="1.0"></sk-directional-light>
<sk-ambient-light intensity="0.4"></sk-ambient-light>
<sk-plain-material id="path-mat" base-color="#8899aa"></sk-plain-material>
<sk-plain-material id="hub-mat" base-color="#e0b040"></sk-plain-material>
<sk-plain-material id="x-mat" base-color="#d1495b"></sk-plain-material>
<sk-plain-material id="y-mat" base-color="#6bbf59"></sk-plain-material>
<sk-plain-material id="z-mat" base-color="#4f86c6"></sk-plain-material>
<!-- A closed 3D curve through the eight corners of a cube. -->
<sk-spline id="path">
<sk-points-spline-source basis="catmullRom" wrap="closed"
points="[[-1.5,-1.5,-1.5],[1.5,-1.5,-1.5],[1.5,1.5,-1.5],[-1.5,1.5,-1.5],[-1.5,1.5,1.5],[1.5,1.5,1.5],[1.5,-1.5,1.5],[-1.5,-1.5,1.5]]">
</sk-points-spline-source>
<sk-stroke-paint material="#path-mat" width="1.5"></sk-stroke-paint>
</sk-spline>
<!-- The follower is a group node carrying the constraint; its children form
a coordinate frame (X red, Y green, Z blue) plus a hub at the origin.
The constraint drives the GROUP, so the frame moves and rotates as one. -->
<sk-scene-node>
<sk-sphere radius="0.28">
<sk-surface-paint material="#hub-mat"></sk-surface-paint>
</sk-sphere>
<sk-arrow orientation="+x" shaft-radius="0.03" shaft-length="0.4" head-radius="0.08" head-length="0.2" x="0.65">
<sk-surface-paint material="#x-mat"></sk-surface-paint>
</sk-arrow>
<sk-arrow orientation="+y" shaft-radius="0.03" shaft-length="0.4" head-radius="0.08" head-length="0.2" y="0.65">
<sk-surface-paint material="#y-mat"></sk-surface-paint>
</sk-arrow>
<sk-arrow orientation="+z" shaft-radius="0.03" shaft-length="0.4" head-radius="0.08" head-length="0.2" z="0.65">
<sk-surface-paint material="#z-mat"></sk-surface-paint>
</sk-arrow>
<sk-align-to-spline-constraint spline="#path" progress="0" tangential>
<sk-animation duration="9000ms" iterations="Infinity" easing="linear">
<sk-keyframe offset="0" progress="0"></sk-keyframe>
<sk-keyframe offset="1" progress="1"></sk-keyframe>
</sk-animation>
</sk-align-to-spline-constraint>
</sk-scene-node>
</sk-scene>
| Attribute | Type | Default | Description |
|---|---|---|---|
splineanimatable |
<id-ref> |
— | The spline to follow, as an AbstractSpline instance or a reference by id |
progressanimatable |
<number> |
0.0 |
Arc-length progress along the spline (0–1). Values wrap cyclically. |
tangentialanimatable |
<boolean> |
false |
Whether the target also aligns its +Y axis to the spline tangent. |
up-vector |
<3d-vector> ([<number>, <number>, <number>]) |
[0, 1, 0] |
Reference up vector used to orient the target when tangential. |