I am trying to make a script that lines up a list of GameObjects. Currently, I do this by generating a set of positions and then lerping the objects to them, the code works but does not account for the object's size so if it is large enough clipping will occur. I don't care if the solution is an improvement to the existing code or something entirely new. This is my current code:
private List GenLinePos(List objs) {
float curHoldOffset = lineOffset;
List<Vector3> positions = new List<Vector3>();
positions.Add(lineAnchor.transform.position);
int side = 1;
for(int i = 1; i < objs.Count; i++)
{
//set initial position
Vector3 pos = lineAnchor.transform.position;
//change position
pos += (lineAnchor.transform.forward * curHoldOffset) * side;
side *= -1;
if(side == 1)
{
curHoldOffset += lineOffset;
}
positions.Add(pos);
}
return positions;
}
Note: the line anchor is parented to the main camera which will be moving and rotating
Renderer.boundsto estimate the spacing needed? \$\endgroup\$lineAnchor.transform.forward, so that gives you the axis. In your application, is that typically aligned to a world axis, or diagonal to them? \$\endgroup\$