S
S
Surface-ketch2016-10-01 15:38:21
Unity
Surface-ketch, 2016-10-01 15:38:21

Jerking movement in 2d unity game?

Good day.
Problem essence: there is an array with two groups of objects:
1 group - sprite renderer + boxcollider2d(trigger);
group 2 - boxcollier2d(trigger);
At the start of the scene, I copy it to list and use it from there.

for (int i = 0; i < poolFloor.Length; i++)
        {
            GameObject setFloor = (GameObject)Instantiate(poolFloor[i]);
            setFloor.SetActive(false);
            pooledFloor.Add(setFloor);
        }

In the update, a simple script that moves the object from the right end of the camera to the left through translate(deltaTime), turning off the object behind the left end of the camera and turning it on near the right.
void Update () {	
        maxX = width * -0.5f; 
      speed = -5f - Time.timeSinceLevelLoad * 0.07f; //скоротсь
      for (int i = 0; i < pooledFloor.Count; i++) {
        if (pooledFloor [i].activeInHierarchy) {
        polledTransformObject[i].Translate(Vector3.right * speed * Time.deltaTime); //двигаем объект
        float floorWidth = pooledBoxCollider[i]; //длина объекта(закеширавно в start())

            float floorRight =  polledTransformObject[i].position.x + floorWidth; //вычисляем крайнюю правую точку объекта

          if (floorRight > maxX) {
            maxX = floorRight;      //находим самую большую точку X
          }

          if (floorRight < cameraLeftX - 1) {
            pooledFloor [i].SetActive (false);  //если объект вышел за левый край камеры, то выключаем
          }   
        }
      }

      if (maxX < cameraRightX+1) {
        NeedNew ();               //если максимальная Х меньше правого конца камеры, активируем новый объект
      }
      
    }

But all this movement goes in jerks from the very beginning, that is, for some time smoothly, some in huge jerks. In the profiler, I showed huge jumps in gfx.waitforpresent, looked at foreign forums, turned on vsync on the advice and reduced the size of the graphics, now the folder with the graphics weighs 700kb, in the junket I riveted everything into two atlases: ui and main. But the situation does not seem to have changed at all, except that the movement has become more blurred due to vsync.
What else could be causing the problem?
PS The movement twitches both in the editor and on the test lumia 535.
What the profiler and settings look like now:
329b5d706a474dbf99cb310d237bd801.png5ad2550bda5d412489667147f120399b.png6508b346778d4477a31afd4bf9915868.png4f2eb45501d040ca8c689a5144dcef49.png
pixel art graphics, I tried different settings, but everything is the same:
74807094a5b34cb0b69acd8f2a240379.png26ff3915ffda4539a7041375292a9759.pnga7ebe6208eda4ef897dad455057a50c5.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Gaydak, 2016-10-01
@Surface-ketch

If the camera is attached to a moving object (on which all this motion script is), then I can assume that the trouble is in this line (although there may still be trouble with the hierarchy and other scripts)
speed = -5f - Time.timeSinceLevelLoad * 0.07f; //Speed
​​Time.timeSinceLevelLoad - may not change evenly, for each frame, and so on. and in general, your speed is constantly growing, if it is necessary, then start your own timer, changing on the update, smoothly. try. So like from the description of other reasons I do not see.
timer+=Time.deltaTime;
speed = -5f - timer* 0.07f; // speed up

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question