path_spline(ENTITY*, VECTOR* pos, var dist)
Movement along a path. This function
calculates a smooth spline curve along a closed loop path, and sets the pos vector
to the calculated curve position that corresponds to the given distance
on the path.
This can be used for smoothly moving actors,
vehicles, or cameras along a path.
ENTITY* - pointer to an entity attached to a path.
pos - vector to receive the calculated curve position.
dist - distance on the path to calculate the curve position
Number of the node before the calculated position.
pos - set to a position on the spline curve.
- This function uses a Hermite polynomial interpolation for calculating
a smooth curve that runs through all nodes of the path.
- The curve connects all nodes in the order of their numbers.
How they are connected through edges doesn't matter.
- The dist parameter corresponds to the distances of straight
lines connecting the nodes, and not to the real
distance of the curve. Thus, when adding a constant speed to the dist parameter,
the real speed along the curve can vary. It is the faster the more
the curve deviates from the straight lines between the nodes. If
this is undesired, place more nodes to avoid deviations at sharp
bends in the path.
The total length of the path can be found through the path_length function.
- Due to the finding of the closest node, the function
is a little faster for smaller dist values.
If dist exceeds
the path length, it begins a new loop on the path.
//call camera_path(""); to let the camera run along a path in the level
// create a dummy path entity
me = ent_create(NULL,nullvector,NULL);
var dist = 0;
// place the camera on the path
dist += 5*time_step;
// let the camera look ahead
path_scan, path_nextnode, path_setedge, path_length