Im trying to make simple 2D game and faced situation where moving objects with transform.position + speedFloat * Time.deltaTime produce visible imperfections.
This is how my scene looks like:
Squares scale values are 1, SquaresHolder position is (-0.5, 0, 0) and SquaresHolder2 position is (0.5, 0, 0)
Here is code attached to both SquareHolders, but isShift=true for left column only
using UnityEngine;
public class TEST_OBJ_MOVEMENT : MonoBehaviour
{
public bool isShift;
float speed = .5f;
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
if (isShift) {
Invoke("ShiftToTop", 2);
}
}
// Update is called once per frame
void Update()
{
if (!isShift) {
transform.position = new Vector3(transform.position.x, transform.position.y - speed * Time.deltaTime, transform.position.z);
}
}
void LateUpdate() {
if (isShift) {
transform.position = new Vector3(transform.position.x, transform.position.y - speed * Time.deltaTime, transform.position.z);
}
}
void ShiftToTop() {
transform.position = new Vector3(transform.position.x, transform.position.y + 1, transform.position.z);
Debug.Break();
}
}
After shift happened columns looks good, without any gaps, but after I unpause game and columns start moving again I see smth like that(1st column is slightly above from the expected position):
I tried to increase orthographic camera size from 5 to 1000 or 10_000, but gap is still present after shift and Im not sure if it break my game later, when columns become longer and have 1000+ squares, perhaps I will go out of possible transform.position values range.
I found some suggestions to use only int values in position, but it doesnt look like a good solution which produce smooth movement and will not create situation where 1st column y value will be 10.99 and rounded to int 10, but other column value will be 11.01 and rounded to int 11.
So is there a good solution how to achieve precisious movement to make movement on the same speed dont cause noticiable gaps between squares in different columns?










