Limiting rotation of a body

Hi all,
in my plateformer game, i want to limit the rotation of my character controller for more realisme, is there any proposition to do that?
If you just want your character never to rotate at all, you can just set fixedRotation to be true in the body def:
Code:
b2BodyDef bodyDef;
bodyDef.fixedRotation = true;

If you want to allow your character a certain amount of rotation so that he is not totally rigid, you could apply a torque to correct the rotation as necessary. This is a little more involved. I am using this code:
Code:
   float desiredAngle = 0;
   float angleNow = body->GetAngle();
   float changeExpected = body->GetAngularVelocity() * timeStepLengthInSeconds; //expected angle change in next timestep
   float angleNextStep = angleNow + changeExpected;
   float changeRequiredInNextStep = desiredAngle - angleNextStep;
   float rotationalAcceleration = timeStepsPerSecond * changeRequiredInNextStep;
   float torque = rotationalAcceleration * torqueAdjustment;
   if ( torque > maximumPossibleTorque )
      torque = maximumPossibleTorque;
   body->ApplyTorque(torque);

It looks quite long-winded but I left it like that so I could figure out what I was doing.
torqueAdjustment is a value which you will need to play with, it alters how quickly the rotation will be corrected. I've found that a value of 3 for this makes my 75kg character look rigid almost all the time, except when he slams into something while running fast. Don't set this value too high because the rotation in the next time step might end up way too far in the opposite direction, causing the next correction to be even larger, etc.
Although this works fine I've always wondered if there was another way.... ?
ah ok thanks for your help 😉
what value should i give to timeStepLengthInSeconds, timeStepsPerSecond, maximumPossibleTorque for a player with 86 as weight, 1/60hz, and 10 iterations ?
timeStepLengthInSeconds = 1 / 60
timeStepsPerSecond = 60

maximumPossibleTorque is up to you. I am using 20000 for my character with mass of 75 and this allows him to correct his rotation so quickly you can hardly tell, except when he slams into a wall or something. http://www.youtube.com/watch?v=diA8TFrs_r4
My characters center of mass is offset though, so he requires more torque to stay up straight. If your character has his center of mass in the center of his shape as normal, you probably won't need so much torque to rotate it.
Your method fodn't work 🙁
here one demo for windows who shows the problem: http://www.assembla.com/spaces/white_night/documents/dRPWcQy7yr3Apwab7jnrAJ/download/demo.rar
it contains two executable, the first with fied rotation, and the second, with your method
Those exe's seem to be invalid, I can't run them.

Unless you really need your character to have some flexibility (most games dont), then I would use the fixed rotation method.
invalid? there si no error message or something like that?
Yes, the message says the executable is invalid 😕
that's beacause i had compile it with VC++ 2008 😉

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