Path: MoveAlongSectionsWithDistances

Move multiple objects along sections for a certain distances and speeds. All parameters are arrays, and all must be of the same length.

If a given object was told (by this function) to move along a section, and a subsequent call gives it the same section, it will start that movement from the end of that call. (i.e. It will resume the movement, but if it isn’t finished, it will ‘jump’ to the end of the first movement.)

This function should be considerably faster than calling MoveAlongSectionWithDistance in a loop.

Note that this function is metric only for the moment. It doesn’t support moving backwards, acceleration, nor deceleration. Section end events are not called.

Function

void MoveAlongSectionsWithDistances(
    sectionIds: Integer[], 
    objects: Identifier[], 
    speeds: Number[], 
    distances: Number[])

Parameters

Name Type Description
sectionIds Integer[] A list of sectionIds to move along. (One based.) objects[0] will move along sectionIds[0], objects[1] along sectionIds[1] and so on.
objects Identifier[] A list of (numeric) object Ids to move. Retrieve this through the Id property of an equipment object.
speeds Number[] The speeds that the objects should move at. objects[0] will move at speeds[0], objects[1] at speeds[1] and so on.
distances Number[] The distances that the objects will cover. If this is less than zero, or greater than the length, the length of the section will be used instead. objects[0] will move distances[0] units along the section, objects[1] distances[1] units along, and so on.

Example

let shapes = GetComponents("Basic Shape");
let objects = new Array(4);
for (let i = 0; i < 4; ++i) {
    objects[i] = shapes[i].Id;
}
let sectionIds = [1, 2, 3, 4];
let speeds = [1.0, 0.5, 0.7, 1.2];
let distances = [-1, -1, 1.0, 2.3];

let path = GetComponentByNameAndType("Path1", "Path");
path.MoveAlongSectionsWithDistances(sectionIds, objects, speeds, distances);
/* The above call is equivalent to
 *      for (let i = 0; i < 4; ++i) {
 *          let distance = distances[i];
 *          let len = path.GetSectionLength(sectionIds[i]);
 *          if (distance < 0.0 || distance > len) {
 *              distance = len;
 *          }
 *          path.MoveAlongSectionWithDistance(sectionIds[i], shapes[i], speeds[i], distance, null);
 *      }
 * But likely faster.
 */