Skip to content

Define a path with a spline

quick start Beginner ⏱ 5 min vgai 0.1.0

Prerequisites: Installed vgai and run the editor

What you'll learn

  • Declare a spline path in a scene (entity `spline` field)
  • Understand that a spline is a runtime curve for path-following
  • Move an object along the curve with getPointAt

What you'll build: A CatmullRom spline path with a marker riding the curve.

Walkthrough β€” Define a path with a spline Β· generated by 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.

  1. 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): the Path entity has a spline with six control points.

    The spline scene in the editor
    A Path entity with a CatmullRom spline.
  2. Enter play β€” the path renders and a marker rides it. A small SplineFollow component reads the curve, draws it as a line, and moves a gold marker along it.

    The spline rendered with a marker
    The CatmullRom curve, drawn as a line with a marker.
  3. The marker follows the spline around the loop. curve.getPointAt(t) gives an evenly-spaced point at fraction t β€” increment t each frame and the marker traces the path.

    The marker partway along the curve
    getPointAt(t) walks the marker along the curve.
  4. It keeps tracing the closed path. With closed: true the curve loops seamlessly.

    The marker further along the loop
    A closed spline loops forever.
  5. 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)