Answer the question
In order to leave comments, you need to log in
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);
}
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 (); //если максимальная Х меньше правого конца камеры, активируем новый объект
}
}
Answer the question
In order to leave comments, you need to log in
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 questionAsk a Question
731 491 924 answers to any question