Skip to content

SplineJoint

GreasedScotsman edited this page Oct 24, 2022 · 3 revisions

Spline Joint

Spline Joints are RigidBody objects that attach to PolyLine paths much like a rollercoaster car follows the track at an amusement park.

Creating a Spline Path

  1. Add a Spline script to an Empty GameObject.
  2. Add a Poly Line script to the GameObject with the Spline script.
  3. Switch to the Spline Edit Mode using the button overlay in the Scene View.

Image

  1. 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 Type of Bezier and toggle the Linear Tangents button in the Spline Inspector overlay found in the Scene view while in Spline 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 the Edit Mode Type to Catmul Rom.

Catmul Rom with SplineJoint Attached Image

Bezier path with Custom Tangents Image

  1. 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.
  2. 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.

Adding a Spline Joint

  1. Create a new GameObject and add a SplineJoint script to it. This will automatically add a RigidBody script to the GameObject.
  2. 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.
  3. Click the Attach to Spline button 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.
  4. 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.
  5. 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 Drive to 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 be Linear X Drive Speed of 2, Position Dampner of 10 and Max Force of 10. Otherwise, you can set these values later with a trigger or event to have the SplineJoint begin following the Spline path.

Clone this wiki locally