I have some problem with manipulation. I want to rotate the body by joystick, I look the tutorial http://www.iforce2d.net/b2dtut/rotate-to-angle and use method
Code: Select all
float nextAngle = bodyAngle + body->GetAngularVelocity() / 60.0;
float totalRotation = desiredAngle - nextAngle;//use angle in next time step
body->ApplyTorque( totalRotation < 0 ? -10 : 10 );
360, body rotate in the opposite direction.
I try to solve this problem by setTranslate, but it is does not always work...
Code: Select all
float bodyAngle = flBody.getAngle();
float roundAngle = round(angle,1);
if(roundAngle == 0 || roundAngle == (float)(6.3)){
flBody.setTransform(flBody.getPosition(), roundAngle);
//System.out.println(" Angle - " + roundAngle + " BodyAngle " + bodyAngle);
}
float nextAngle = (float) ((bodyAngle + flBody.getAngularVelocity() / 60.0));
float totalRotation = angle - nextAngle; //use angle in next time step
flBody.applyTorque( (float) (totalRotation < 0 ? -0.5 : 0.5) );