Documentation
The SplinePath component
SplinePath is a component that allows to move a node along a path defined from a series of nodes acting as 'control points'. The node to move is called 'controlled node'.
Building the path
A path is built from ordered points. When setting the points from nodes using AddControlPoint(), an index is used to order them. At least two nodes are required to build a path.
Removing points from the path
Points can be removed:
- either individually using RemoveControlPoint().
- or globally using ClearControlPoints().
Assigning the controlled node
The controlled node is assigned using SetControlledNode().
Moving the controlled node along the path
The controlled node is moved manually according to a time step, using Move() in your update function.
Behavior controls
The behavior of the node is mainly influenced by its:
- speed.
- interpolation mode used to follow the path. Available modes are BEZIER_CURVE, CATMULL_ROM_CURVE, LINEAR_CURVE and CATMULL_ROM_FULL_CURVE.
Taking manual control of the controlled node
The control node position can be:
- reset to the starting position (first point in the path) using Reset().
- set to a given position of the path using SetPosition(). Position is expressed from 0.f to 1.f, where 0 is the start and 1 is the end of the path.
Querying spline path informations
At any time you can query:
- the speed.
- the path length.
- the parent node's last position on the spline.
- the controlled node.
- a point on the spline path from 0.f to 1.f, where 0 is the start of the path and 1 is the end.
- whether the destination (last point of the path) is reached.
Debugging
As for any component, a debugging function is supplied to visually check the component.
Sample code
The following sample demonstrates how to build a path from 2 points, assign a controlled node and move it along the path according to speed and interpolation mode.
In your update function, move the controlled node using Move():