# Instatiate on a path

hey i need help instantiating a number of objects evenly on a path. for example i have a path of random vectors or transform positions, and need to create a number of objects evenly and in form along the path. I basically need pointers to the right math techniques to get the right position of each object so they fit on the path

This is a less elegant and more brute force approach: the objects are evenly distributed at a constant distance measured strictly along the path, and aligned to the segment where each one is created. An auxiliary array showing the distance of each node to the first one is created, and used to calculate the positions in the segments between nodes:

```var goNodes: GameObject[]; // array of nodes
var prefab: GameObject;

function CreateObjects(qnt: int){
var sz = goNodes.length;
var nodes: Vector3[] = new Vector3[sz]; // node positions
var distances: float[] = new float[sz]; // node distances
//** use a LineRenderer to show the segments between nodes:
var lineRendr: LineRenderer = GetComponent(LineRenderer);
lineRendr.SetVertexCount(sz);
// initialize node positions and distances:
var dist: float = 0;
var lastPos: Vector3 = goNodes[0].transform.position;
for (var i=0; i< sz; i++){
var nodePos = goNodes*.transform.position;*
_//** define the vertices based on the nodes:_
*lineRendr.SetPosition(i, nodePos);*
*dist += (nodePos-lastPos).magnitude;*
_nodes *= nodePos;*_
_distances *= dist; // distance along the path*_
_*lastPos = nodePos;*_
_*}*_
_*// find the desired distance between objects:*_
_*var objSpace = dist/(qnt-1);*_
_*// initialize conditions to create 1st object*_
_*lastPos = nodes[0];*_
_*var curNode: int = 1;*_
_*var objDist: float = 0;*_
_*var lastDist: float = 0;*_
_*for (var n=0; n< qnt; n++){*_
_*// find direction of current segment:*_
_*var dir = (nodes[curNode]-lastPos).normalized;*_
_*// find position in current segment:*_
_var pos = lastPos+dir*(objDist-lastDist);_
_*// create the object:*_
_*Instantiate(prefab, pos, Quaternion.LookRotation(dir));*_
_*objDist += objSpace; // find next object distance*_
_*// find segment where to put next object:*_
_*while (objDist>distances[curNode] && curNode< sz-1){*_
_*lastPos = nodes[curNode];*_
_*lastDist = distances[curNode];*_
_*curNode++;*_
_*}*_
_*}*_
_*}*_
_*function Start(){*_
_*// example:*_
_*CreateObjects(6);*_
_*}*_
_*```
*_

EDITED: I modified the script above to include lines between segments with a LineRenderer - add the LineRenderer to the object to which this script is added, and set its parameters (specially Parameters/Start Width and End Width, and Material - or you will get awful pink lines connecting the nodes!).
A more 3D alternative would be to create cylinders or cubes connecting the nodes - they could be simple meshes without colliders, and using a semitransparent material, for instance - take a look at [this question][1], where a simple script dynamically stretch a cube to connect two objects.