Define a path with a spline
site/media/lessons/learn-scenefeats.lesson.ts (5 steps) A spline is a smooth path through control points. You declare it on an entityβs spline
field; the engine builds a Three.js CatmullRomCurve3 and stashes it (in userData.splineCurve)
for gameplay to follow. This scene defines a closed spline and a small component rides a marker
along it.
-
Open the scene. The scene is already open β if you followed the link above, the splines scene is loaded and rendering (in the local dev editor:
VGAI_PROJECT=examples/learn-splines npm run dev): thePathentity has asplinewith six control points.
A Path entity with a CatmullRom spline. -
Enter play β the path renders and a marker rides it. A small
SplineFollowcomponent reads the curve, draws it as a line, and moves a gold marker along it.
The CatmullRom curve, drawn as a line with a marker. -
The marker follows the spline around the loop.
curve.getPointAt(t)gives an evenly-spaced point at fractiontβ incrementteach frame and the marker traces the path.
getPointAt(t) walks the marker along the curve. -
It keeps tracing the closed path. With
closed: truethe curve loops seamlessly.
A closed spline loops forever. -
Stop play mode.
// learn-splines.vscn.json β the Path entity"spline": { "curveType": "catmullrom", "closed": true, "points": [[-5,0,-3],[-2,1.5,3],[3,0,3],[5,2,-2],[1,1,-4],[-3,0.5,-1]] }Recap
New functionality
- Declared a spline path in a scene
- Moved a marker along the curve
New concepts & skills
- A spline is an entity `spline` field β a THREE CatmullRomCurve3
- At runtime it's data (userData.splineCurve) for path-following, not auto-drawn
- curve.getPointAt(t) gives an evenly-spaced point to follow
Next lesson β Scenes & prefabs
On Your Own!
Extend what you built:
- Change the control points and watch the path reshape
- Set closed:false and see the marker stop at the ends
- Orient the marker along the curve tangent (getTangentAt)