PathCreator is a tool for creating Bezier curve splines in the Scene view. These splines can be used to represent a path agents use to move. You can place objects and meshes along it for example to create roads. Read more about Bezier curve and how it is defined parametrically here or watch this in-depth video.
To start creating a spline add a PathCreator component to any game object. Default spline with two anchors and two control points will be added to the scene.
Adding a game object with PathCreator to a parent with significantly changed scale will result in spline having a huge initial size which is inconvenient to work with. In this case it is recommended to first create a game object with PathCreator at the top of the hierarchy and then add it as a child.
Each segment of the spline is defined by two anchor points that determine the start and the end of the spline and two control points tied to anchors that determine the shape of the spline . When more segments are added intermediate anchors have two control points each determining the shape of neighbouring spline segments. To keep the spline curve smooth those control points are usually tied to each other and placed on a straight line but it's possible to change that using different Control Modes.
To have more control over the spline shape you can choose how a control point opposite the one you are manipulating behaves:
Mirrored mode will place the opposite control at the same distance from anchor and directly opposite direction as the manipulated one.
Aligned mode changes the direction of the opposite control but keeps the original distance to anchor intact.
Free mode completely decouples two controls and allows changing them independently.
Automatic mode will place all control points automatically maintaining the smooth shape of the spline.
Enables snapping of anchor and control points to the nearest surface. It can be useful if you want to create a ground path on an uneven surface. Snap mode uses anchor position to calculate the snapped positions of related controls so make sure to snap the anchor first by moving it until it snaps to the surface you want.
For best snapping accuracy it's recommended to manually set up Surface Orientation in corresponding dropdown.
Surfaces with complex shapes or frequently changing angles can still lead to inaccuracies. Placing anchor points on each surface with different angles should help. If all fails you can always disable snapping mode, set up the problematic segment manually and then enable snapping mode again.
Choose between creating splines in 3D or 2D space, with 2D splines restricted to the XZ plane. Snapping is only available in 3D space.
Opening Normals Options section will make normals visible. They determine the orientation of objects placed on a spline or moving along it. While you can set the global angle of normals it's also possible to fine tune them for each segment by clicking on anchor and enabling Unity's rotation tool by clicking on corresponding icon or pressing "E".
Constant Point Size makes it so that control and anchor points keep the same size when moving closer or farther from spline.
Global settings that also exist in Path Options (snap to surface, etc.) determine defaults when path is created or reset.
Deselect When Clicking Outside Spline determines if selection is changed if you click on empty space or other game object. If it's disabled you need to click anywhere in the Hierarchy window to deselect PathCreator object.
Append: Shift + Left Mouse Button (LMB).
Prepend: Ctrl + Shift + LMB or Command + Shift + LMB on Mac.
Divide: Shift + LBM over a segment.
Delete Anchor: Ctrl + LMB or Command + LMB on Mac.
While Bezier Path tab shows a visualization of the spline, Vertex Path shows an actual curve that is created by sampling the curve equation at certain intervals. This allows to get a set of vertices which can be used while moving or placing objects along spline.
Vertex Path Options determine how close the resulting curve will resemble the original one. Changing the margins of error will reduce the Vertex count making it more lightweight while losing some degree of fidelity.
We've created a simple SplineMovement with MoveAlongSpline node. The code behind this node shows how spline points can be sampled programmatically to determine position and orientation of the agent on the spline. Example behaviour tree can be found at Assets/AnythingWorld/Examples/BTMovement.
To see it in action open and run RandomMovement scene from the same folder. You can also see a more specific use case by downloading Extra scenes package from the bottom of your profile page and running City_Day scene.
You can also add this BT to any game object to make it move along spline. Adding behaviour trees is explained in the previous section of documentation. After adding the BehaviourTreeRunner component and choosing SplineMovement as the BT you want to run, you also need to add a MovementDataContainer script which contains a field for PathCreator. Add your game object containing PathCreator component to this field and you are good to go.
It is also possible to create a spline programmatically at runtime by using one of the constructors in BezierPath
class. All you need to do is supply it with a set of 2d or 3d points and optionally specify if you want the spline path to be forming a loop and space of the path to be 3d or 2d.