Need to fix a small gap between two objects, which created by code

Hi, guys!

I’m working on endless runner game. I’m creating the prototype now. Game world created from some prefabs (ground parts), which were preloaded from an array. Some kind of pooling system. Whole game world creates from 3 ground parts/blocks, which sticks and moves together. All these first blocks/prefabs placed by code in one JS file, which attached to an Empty Game Object (some kind of World Inspector). Those tree blocks stick perfectly without any gaps (visible seams) between them.

When first block moves out of the screen I deactivate it and place the new one at the end of the stack. Check for deactivating the object happens in other JS file, which is connected to a prefab/block itself. And here the problem appears. Every new blocks I’ve created have a small seam/gap between him and others blocks.

Here you are some check code sample:

 // If object is out of screen, than...
    if ( transform.position.z <= -30 ) {
    GameObject.Find("Pool Inspector").GetComponent(objectsPoolingScript).PrefabPlacement(false); // Execute the function for new prefab activation
    gameObject.SetActive (false); // Deactivate the prefab, which is out of screen
    transform.position.z = 0.0; // and reset its position

When I’ve checked Z position of the object I saw that my check executes not in perfect -30.0 value, but something around -30.045 value. Those value changes time to time. So, I think that this .045 is a gap problem. But I can’t understood how to fix it and why is it happen? Maybe there’s a delay between send some values from one script to another? But how to fix it?

So, maybe you, guys, will able to help me to settle it? Thanks.

You did not show much of your code, so I’m left to guess a bit. The overlap of -30 will occur if you use Time.deltaTime to scale your movements. Or if you are using some fixed scale, it will occur when the movement rate does not evenly divide into -30. There was an almost identical questions asked just a few hours ago:

A fix is to compensate for the overlap. So in your case, you might set

transform.position.z = transform.position.z + 30;

Another fix might be to select a speed that evenly divides into length, and use FixedUpdate().

did you fix it, i’m facing the same problem