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'.
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.
Points can be removed:
The controlled node is assigned using SetControlledNode().
The controlled node is moved manually according to a time step, using Move() in your update function.
The behavior of the node is mainly influenced by its:
- interpolation mode used to follow the path. Available modes are BEZIER_CURVE, CATMULL_ROM_CURVE, LINEAR_CURVE and CATMULL_ROM_FULL_CURVE.
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.
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.
As for any component, a debugging function is supplied to visually check the component.
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():