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?
Asked
Active
Viewed 3,721 times
1

Igor Sova
- 23
- 1
- 5
-
What happens when you use `ApplyTorque()` on your plane? – Ebbe M. Pedersen Sep 05 '13 at 15:19
-
@ebbe, my plane infinitely spin after changing joystick position. I use code for torque rotation from the site below: http://www.iforce2d.net/b2dtut/rotate-to-angle – Igor Sova Sep 05 '13 at 16:09
3 Answers
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
-
Hey, look at my comment above. I think, i do something wrong, but i can't understand what. – Igor Sova Sep 05 '13 at 16:33
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.

Parth Parikh
- 16
- 2
-
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);

Umair Malik
- 9
- 3