Jittery world around stationary character

Summary:

I am creating an infinite runner. I have an object in my scene that is permanently moving to the left (“Scroller”). Whenever I create obstacles, I parent them to the “Scroller”. Once they move off screen, I set them to inactive.

The player object does not move at all, nor does the camera. Both of these objects are 100% stationary, as the Scroller object is doing all of the movement.

Problem:

The movement of the one parent object is jerky in the editor (thus causing the children objects to jitter), and there is very jerky movement in non-development WebGL, PC and Android build.

More Details and Reiteration:

  • Each obstacle has a rigidbody attached.
  • The jitter occurs randomly, sometimes few seconds, sometimes every frame.
  • There are no more than 20 obstacles active at any point in time.
  • Only the “Scroller” object is moving, and every other object is being parented to it
  • I am instantiating one of many Obstacle collections, and then parenting that collection to the “Scroller.”

To reiterate that last point, my hierarchy looks like - Scroller → Obstacles Parent - > Obstacle, Obstacle, Obstacle

Script

My movement script:

    private void Update()
    {
        scroller.position = Vector3.Lerp(scroller.position, scroller.position + new Vector3(-1, 0, 0), Time.deltaTime * speed);
        //scroller.position += new Vector3(-1, 0, 0) * (Time.smoothDeltaTime * speed);
    }

Using LateUpdate provides roughly the same experience, give or take a few hairs from my head.

@Shingox It’s not clear as to whether you’re talking about is “jittery” framerate or jittery movement with the physics and whatnot.

If it’s framerate, a stutter every now and then could be related to garbage collection. If you’re constantly creating new object and not getting rid of the old objects I imagine you’ll just run out of memory at some point. Re-using the deactivated objects is what you want to do, ideally.

If it’s some issue with the physics, I can imagine physics would be wonky if you’re scrolling the entire environment that everything is standing on. Instead of scrolling the ground, just keep a physics object for the ground as a static object and move everything else around it. Just an idea, anyway. Try different types of hierarchies until you find something that works for you.