1

I am a newcomer in game dev and i didn't have deal with box2d and cocos2d-x before. So I have some troubles. I have a plane in my game, so when user turns joystick in one of directions, plane should turn in this direction. How can i do it? I think SetTransform() is a bad idea, so I should use ApplyTorque() for natural look of this action? Can anybody give me an example of using ApplyTorque() for that situation?

Igor Sova
  • 23
  • 1
  • 5

3 Answers3

0

http://www.iforce2d.net/b2dtut/rotate-to-angle

http://box2d.org/forum/viewtopic.php?f=3&t=9443&view=previous

These are tutorials to rotate a body by a certain angle..

Hope these help.

aug13
  • 369
  • 4
  • 6
0

If you want to know how to code for box2d body you should reference http://www.iforce2d.net .

To rotate body you can apply torque or apply force on the ending point of the body. after it got rotated apply ApplyLinearImpulse() method of box2d to it.

Change position of graphics by referencing box2d body.

tell me if can't get this.

  • changing position works pretty good for me. Problem in rotating with torque. Yes, I read, that there are some problems, when the center of mass not in (0, 0), but I changed it to this position and it's don't work. ApplyAngularImpulse() works good for me, I don't know what's the problem – Igor Sova Sep 06 '13 at 09:03
0

First convert the rotation from Degree to Radians Then Set Transform of The Body like this

float32 RotateToAngle = 1 * CC_DEGREES_TO_RADIANS(90);//change 90 Degree to radians

body_->SetTransform( body_->GetPosition(), RotateToAngle);