- Home /
How to make game objects move at exactly the same time
Hello, I have been working on a 2d game for a while now using c sharp and I have a problem. I am looping through some game objects (2 or more) and instructing them to move in a certain direction. I want them to all appear to move at the same time, however the slight delay in unity's loops causes this error / dealignment of the objects (pictured here in the left example, the right example being the intended outcome).
I need a way to fix this, so please help if you can.
Here is the code :
for (int a = 0; a < Movables.Count; a++) {
if (Movables[a].Left.movableBlock.Length > 0) {
Collider2D movable = Movables[a].Left.movableBlock[0];
movable.GetComponent<MovableBlock>().MoveLeft();
Movables[a].MoveLeft();
} else {
Movables[a].MoveLeft();
}
}
EDIT : I have already tried making all the objects wait for a boolean to change in the master script, but this had the same outcome.
There's no such thing as "unity 's loop delay". Physics engine works with some frequency (you can set it Edit->Project->Time->Fixed Timestep). So if you move 50 objects in your FixedUpdate (using a loop or whatever else), they're all gonna be moved at the same "frame". Post your $$anonymous$$ovableBlock
class
Thanks for the help, fixed it by just putting the code in the Fixed Update.
Your answer

Follow this Question
Related Questions
Making a bubble level (not a game but work tool) 1 Answer
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Input.GetAxis not returning to zero after key is released 0 Answers