How to make objects move in Synchronisation

Hi guys, I’m having an issue at the moment where, for example, I have two platforms, I want one to move right 5 metres at a rate of 5 metres per second, and one to move down 1 metre at a rate of 1 metre per second. I want both platforms to pause for 0.5 seconds at their targets, to return to the original position at the same speed. This would equate to the objects being perfectly in synch with eachother. However, due to the imprecision of floating point maths, often these objects reach their initial or ending points at different times, due to moving something like 0.005 metres too short of their target when the other reaches it. Meaning over time the platforms become notably out of synch. Can anyone think of, or suggest a good way to ensure that this does not happen? I tried out a series of things, using lerps. Having each object contain a list of “partners” that each platform will wait for before starting again, but none of these implementations are perfect and are far from simple sublime solutions. Is there a better way to be doing this?

Is it possible to animate the platforms? Well, yes it is possible, but is it suitable for your purpose? You should give it a try. Another way would be to hold one platform until the other has reached its key position, then allow both to move again. You could check at both ends of the movement.

–

Post your code. I can see them starting out not in sync, but correctly coded, and driven off the same timer, they should not get out of sync. You want to make sure you are correcting positions at the end positions and that you are tying events to absolute time positions.

–

1 Answer

1

My solution to this was to have a parent object of all the platforms track whether they are at their half way of finished points, and keep a int for each object, if the objects need to stay in synch they all have to wait until the parent script states that all objects are at either half way or end.

The key point here is that I also needed to use an int with a value of 2 that would be reduced every frame, rather than having a bool that would be set to false as soon as a platform has moved away. That way I can ensure that when one object moves and is no longer at the end/mid point (and thus the “are all platforms at mid/end” value will now be false) it won’t prevent all platforms that execute after the first platform not moving, because it is still true for another frame.