Uncontrollable Stuttering

Hello,

I'm using Box2D for a 2d Car Simulation. While the car drives forward, the ground and some obstacles are moved backward.
This Movement sadly isn't constant, it goes like this per frame: 7px, 7px, 7px, 7px, 3px, 7px, 7px, 11px, px, 7px,....
Sometimes the movement is just half as much as the frame before. Any ideas?
My whole simulation consinsts ob my car, 4 bounds and about 200 simple objects like circles or rectangles.
did you use a fixed timed step for your physics? If you use a variable time step it tends to stutter a bit.
Sorry for my late response, I didn't get any e-mail notification.
I used a fixed timestep which I set to 1/30 which matches with my framerate. I couldn't
resolve the probleme to date. Some other suggestions?
(I'm now turning e-mail notification on 😉)

I just compiled a small example which I uploaded here:
http://www.funfury.de/up/car.rar
http://www.funfury.de/up/car.swf (unrared)
You'll notice that the environment stutters from time to time while the CPU isn't used so much that it could cause the stuttering. I was using Box2D, her's some of the important Lines:
Code:
simulation = new QuickBox2D(main, draw, {debug:false, bounds:[0, 0, Conf.levelWidth, 15], timeStep:1/30, iterations:30, frim:false});
simulation.setDefault({frequencyHz:30});

There is an enterFrame event which executes:

simulation.onRenderFromScene();

The background Movement is synchronized whith these lines:
Conf.curSpeed = -(lastPos - carBody.body.GetPosition().x);
this.x = -carBody.body.GetPosition().x * 30 + 300;

the curSpeed is then used to move all Objects in the background.
It might be the hour, but I don't see any stuttering.
Watch the trees, they're moving kinda unsteady and sometimes they seem to hang for a short time.
Oh yes, I see it now.

Are the trees being moved by Conf.curSpeed ?
I have a feeling it's lastPos that's causing trouble. When and where are you updating the last position?
The trees are using Conf.curSpeed multiplied by a factor based on their distance to the viewer.
I think I stripped a bit too much code away, here's the whole part around lastPos:
Code:
         //Calculate car speed and position
         Conf.curSpeed = -(lastPos - carBody.body.GetPosition().x);
         lastPos = carBody.body.GetPosition().x;
         this.x = -carBody.body.GetPosition().x * 30 + 300;
         Conf.curPos = -this.x;
         lastTimer = getTimer();
         if(Math.abs(Conf.curSpeed) < 0.02) Conf.curSpeed = 0;

I don't think lastPos has to do something to do with it. But I do think that it's a failure from the simulation. I think that the error is already visible in the simulation. There are some irregularities in the movement of the car, the landscape around just reproduces and magnifies the errors, so they're even more visible.
Yes, how are you moving the car? Maybe its own movement is causing itself to stutter.
The car is solely moved by the tire rotation which is augmented by a constant every frame. I also tryed removing all obstacles from the simulation, but the stutter persits.
This might be a long shot, but...
Do you rotate both wheels?
Do you have friction between the wheels and the ground?
Try running this again using a single rotating wheel instead of the entire car, does it still stutter?

Original thread: https://box2d.org/forum/viewtopic.php?t=5139