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.
Parameters:
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
for.
Returns:
Number of the node before the calculated position.
Modifies:
pos  set to a position on the spline curve.
Speed:
Medium
Remarks:
 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
function camera_path(pathname)
{
// create a dummy path entity
me = ent_create(NULL,nullvector,NULL);
path_set(me,pathname);
var dist = 0;
var vLastPos[3];
var vDir[3];
while(1)
{
// place the camera on the path
path_spline(me,camera.x,dist);
dist += 5*time_step;
// let the camera look ahead
vec_diff(vDir,camera.x,vLastPos);
vec_to_angle(camera.pan,vDir);
vec_set(vLastPos,camera.x);
wait(1);
}
}
See also:
path_create,
path_scan, path_nextnode, path_setedge, path_length
► latest
version online