void Update()
{
if (animateLines)
{
counter++;
for (int i = 0; i < allLines.Length; i++)
{
Vector3 endPos = allLines[i].GetComponent<EndHolder>().EndVector;
Vector3 startPos = allLines[i].GetComponent<LineRenderer>().GetPosition(0);
Vector3 tempPos = Vector3.Lerp(startPos, endPos, counter / 500f * speed);
allLines[i].GetComponent<LineRenderer>().SetPosition(1, tempPos);
instancesToMove[i].transform.position =
Vector3.MoveTowards(endPos, startPos, counter / 500f * speed);
}
}
else
{
counter = 0;
foreach (GameObject thisline in allLines)
{
thisline.GetComponent<LineRenderer>().SetPosition(1, thisline.GetComponent<LineRenderer>().GetPosition(0));
}
}
}
The lines are LineRenderer.
void SpawnLineGenerator(Vector3 start, Vector3 end, Color color)
{
GameObject myLine = new GameObject();
myLine.tag = "FrameLine";
myLine.name = "FrameLine";
myLine.AddComponent<LineRenderer>();
myLine.AddComponent<EndHolder>();
myLine.GetComponent<EndHolder>().EndVector = end;
LineRenderer lr = myLine.GetComponent<LineRenderer>();
lr.material = new Material(Shader.Find("Particles/Alpha Blended Premultiply"));
lr.startColor = color;
lr.useWorldSpace = false;
lr.endColor = color;
lr.startWidth = 0.1f;//0.03f;
lr.endWidth = 0.1f;//0.03f;
lr.SetPosition(0, start);
lr.SetPosition(1, start);
}
So I have lines each new gameobject have a LineRenderer component and inside Update I'm animating the lines with some speed.
Now I want to move the instancesToMove (GameObject[] ) with the same speed as the lines but the instancesToMove are moving much slower then the lines.
I tried:
instancesToMove[i].transform.position =
Vector3.MoveTowards(endPos, startPos, speed);
Then
instancesToMove[i].transform.position =
Vector3.MoveTowards(endPos, startPos, speed * Time.deltaTime);
But it's never moving with the same lines speed.
Vector3 tempPos = Vector3.Lerp(startPos, endPos, counter / 500f * speed); allLines[i].GetComponent<LineRenderer>().SetPosition(1, tempPos); instancesToMove[i].transform.position = Vector3.MoveTowards(endPos, startPos, counter / 500f * speed);? It's not obvious what behaviour you're trying to create. A short video or gif of the result might help clarify it. Note that framerate adjustment withTime.deltaTimeis absent from the lines above, so your movement will be different at different framerates. \$\endgroup\$