- Home /
Trying to move all child gameobjects at the same speed
Hello, I have a child game object that is not matching up with the rest of the child game objects when it comes to its speed. This 1 child object moves faster than the rest of the child game objects when they should all move the same speed when the function is called. I don't know what's causing this.
public float speed, radius;
Vector3 v;
foreach (Transform child in transform)
{
if (Vector2.Distance(child.transform.position, v) < radius)
{
{
child.transform.position = Vector2.MoveTowards(child.transform.position, center.position, -1 * speed);
}
}
}
There's nothing obvious from this code - is there any chance you also have a script attached to that particular child also telling it to do the same thing? Or is there any code anywhere else in your project that affects that child? What happens if you just delete that child, and duplicate one of the others to repalce it?
theirs no other script attached to the child game objects just its transform component & I'm going to try your suggestion
I got the same result, I noticed it happens for the first element I also tried to do
Transform[] allChild = GetComponentsInChildren(); foreach (Transform child in allChild) { if (Vector2.Distance(child.transform.position, v) < radius) { { child.transform.position = Vector2.$$anonymous$$oveTowards(child.transform.position, center.position, -1 * speed); } }
but same result.
Answer by Batuhan13 · Feb 24, 2020 at 05:44 AM
Hi mate good morning .How many child do you have ?When I was making project about AI some bots were starting move early from other bots if there are lots of bot 5k-10k maybe this cause of your problem .Have you ever tried to delete that children and duplicate normal children ?
Your answer

Follow this Question
Related Questions
Making a bubble level (not a game but work tool) 1 Answer
Distribute terrain in zones 3 Answers
Movement speed doesn't change with variable C# 1 Answer
Bullet not moving from script 3 Answers
Can't change the speed of a character. 2 Answers