-
Notifications
You must be signed in to change notification settings - Fork 41
SplineJoint
GreasedScotsman edited this page Oct 24, 2022
·
3 revisions
Spline Joints are RigidBody objects that attach to PolyLine paths much like a rollercoaster car follows the track at an amusement park.
- Add a Spline script to an Empty GameObject.
- Add a Poly Line script to the GameObject with the Spline script.
- Switch to the
Spline Edit Modeusing the button overlay in the Scene View.

- Draw out a desired spline path by adding Knots and setting their locations. Select a Knot by dragging a selection box around the Knot icon while in Spline Edit Mode. To keep the path linear and use sharp corners, use the
Edit Mode Typeof Bezier and toggle theLinear Tangentsbutton in theSpline Inspectoroverlay found in the Scene view while inSpline Edit Mode. The Bezier Mode also gives you preciese control over the Tangent values of each Knot. To create paths that automatically smoothly curve between Knots, switch theEdit Mode Typeto Catmul Rom.
Catmul Rom with SplineJoint Attached

Bezier path with Custom Tangents

- At the end of the path, choose whether to Close the spline so it becomes a loop or leave it open so it has clearly defined start and end points.
- Ensure the Poly Line script's Spline Container field references the Spline GameObject and click Bake PolyLine. This will fill the Line Data field in the Poly Line script.
- Create a new GameObject and add a SplineJoint script to it. This will automatically add a RigidBody script to the GameObject.
- SplineJoints can have One, Two or Four Contact Points. If making a Skyhook-style track or simply want an object to travel along a path using its center, one contact point should suffice. If creating a mine cart that will have 4 individual wheels riding the track, four contact points can be used.
- Click the
Attach to Splinebutton on the bottom of the Spline Joint script. This should automatically align the Spline joint so that its primary Axis is Z (0,0,1) (forward) and its Secondary Axis is Y (0,1,0) (up). If using Catmul Rom, the green axis indicators of the Spline path and the Spline Joint should be parallel. - Make an empty child GameObject of the SplineJoint and add the meshes or other visual indicators for the object that will travel the Spline path.
- Because the primary Axis is set to Z (0,0,1) and the Secondary Axis is set to Y (0,1,0), the local X-axis of the Spline Joint is its new "forward" direction along the track. Set the
Linear X Driveto a non-zero number if you want the SplineJoint to begin travelling the path on level load. You must also set Position Dampner and Maximum Force values. Reasonable values for a slow-paced object with Mass of 1 would beLinear X Drive Speedof 2,Position Dampnerof 10 andMax Forceof 10. Otherwise, you can set these values later with a trigger or event to have the SplineJoint begin following the Spline path.