- Home /
Stuttering/jerky movement of kinematic rigidbody 2d moving by velocity in 2D game on iOS
Hi, I'm working on a 2D game (unity 5.6.3) that has obstacles moving from right to left with a stationary camera and a player that moves only along the y-axis. I have this problem where the obstacles periodically stutter (or shift backwards and forwards) when moving every 2-5 seconds or so. It is hard to notice for some people, but I always see it.
Each obstacle is moved by a parent object with a kinematic rigidbody2D (interpolation is on) by setting the obstacles velocity once when the object in set to active and has two child objects that each have a box collider 2D. I have the obstacles in a pool (a stack) and they are added back to the stack when they are not needed and then popped back when the are needed.
Their movement is like so inside update (but is only called once when canMove):
if (!hasStartedMoving && canMove && !isDead) {
rigidbod.velocity = Vector2.left*(moveSpeed*addedSpeed);
hasStartedMoving = true;
}
Note: I also see the same stuttering if the movement is by transform.Translate
I have a few TextMeshProUGUI objects with text that pops up as the game plays and sometimes this can occur at the same time as the stuttering, however a lot of the time the stuttering happens on its own. There is one level/scene in the game that is loaded again after game over and I have noticed that the stuttering gets less frequent and sometimes doesn't occur after a few minutes, so I was thinking perhaps it's something to do with text meshes?
I have attempted profiling in the editor as well as on the device, but do not see any spikes (I could be wrong) in performance that correlate with the stuttering. I also can't seem to find any drops in fps below 60 (I also can't see any vsync, which I don't know why), so i'm quite confused about the stuttering.
Here are some screenshots of profiling with an iPhone SE of some spikes (although they are below 60fps).
I also see "Unaccounted time between: ..." quite a lot Does anyone have any ideas as to how I may fix this stuttering or what may cause this? I am open to any ideas as this has been plaguing me for weeks.
Thanks
Your answer
Follow this Question
Related Questions
Character won't move (Fixed) 1 Answer
Object jitters when the scene starts 0 Answers
Weird Rigidbody2D.velocity.x problem, float out of control 0 Answers
can't move player rigidbody.velocity 1 Answer
Rigidboy.velocity with integer? 1 Answer