SOLVED: Problem with prismatic joint speed.

Hello, I have problem with prismatic joint speed.
There I have two bodies connected with a prismatic joint, I set joint's motor speed to 0.5, and it travels distance of 0.8 in ~9s.

If i set the speed to 5.0, the movement is much faster.

Correct me if I'm wrong: the speed is expressed in m/s, and distance in m, so expected time should be near 1.6 s
With a finite max motor force, it takes some time to accelerate up to speed. This depends on many factors, including:
- the mass of the attached bodies
- the forces acting on the attached bodies
- other constraints

Box2D is tuned for meters and seconds, but it does not require a particular unit system. It uses the dimensions you provide as-is. There is no unit conversion.
OK, so I've checked everything, but problem still persist.

- I'm sure the motor reaches it's maximum speed. I've applied huge force, and connected bodies are light as a feather.
- when creating joint, in joint definition motorForce=1e+10, motorSpeed=0.5
- b2World::Step() is called every 100ms, with timestep=0.016667, iterations=6 (which is expected to give 60 iterations per second)
- I'm sure there is no friction - joint is created with collideConnected = false, moving element don't touch anything else
- dumping is turned off.

Still, moving object by 0.8 with speed 0.5 takes 9sec of simulation time.

Any ideas, suggestions? Is there something I didn't check?
Now I've just discovered, that my entire simulation works in slow-motion. And it look like i just got the b2Wolrd::Step() params all wrong. The second para m(iterations) has nothing to do with number of actual steps performed, its just some solver param.

I just didn't RTFM 😳

So now i changed following code:
Code:
_pPhysicalWorld->Step( timeStep, iterations ); // THIS IS SO WRONG!!!


to
Code:
   for( int i = 0; i < iterations; i++)
   {
      _pPhysicalWorld->Step( timeStep, 10 );
   }


My fault.
My experience is that you want to run the world step exactly once per simulation step, as running more than one world step per frame leads to problems. Each step clears all accumulated forces, so all iterations after the first have no forces applied. As a result, effective forces scale inversely proportional to the number of iterations (i.e. 10 iterations make effective forces 1/10th as strong).

You can get away with this if you exclusively apply impulses instead of forces, but I definitely recommend against it. Unless your simulation logic is extremely expensive, you should run it every world step (1/60th of a second in your case). It'll make it a lot more responsive.

In addition, the continuous collision detection (CCD) functionality in the SVN builds and upcoming version 2.0 allows fast-moving objects like bullets to work correctly at surprisingly low simulation rates. My top-down frantic-arcade-action-shooter uses a SVN build of Box2D and tolerates simulation rates as low as 10Hz, but that's only because it has no gravity pulling objects together into big piles (a case giving physics engines a hard time).
At the very least, if you're going to do multiple steps per frame, re-apply all your forces before each one, and make sure to carry out any game logic - you really don't want to miss a player getting killed by an enemy because the collision event only lasted one step and was gone by the time you checked for it.

I often use multiple physics steps per frame, because if you have the cycles to burn, it's an easy way to do a motion blur if you draw with some alpha at each substep (http://www.slimearena.com/hackeysack.php does this with 10 steps per frame for the ball, if I remember right). If you're doing a big simulation, this won't be very useful, but if you've only got a few items on screen, it works quite well.

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