Box2d static and kinematic rotation problem

hi Box2d community ..

Im a new at Box2d and cocos2d and game development , i try to developing some game and stick in strange problem !!

Actually i'm facing problem with rotating body that not dynamic (static and kinematic) ,
i try to put a dynamic box in the top of screen and let it fail depending on the gravity , and i put in the end of screen a static box , every thing seems going well , the daynamic box fail and collide with static box and stop (because the static box blew him) BUT i need to rotate the static box aroud scrren center , i did this by using

Code: Select all

body->SetTransform(newPosition,angle);

and the body seems rotated BUT the problem that the dynamic box stick in his position (the position where it stop when it collide with the static box), after transform the static box the dynamic box stick and dose not continuo failing !!!

I do not know what i must do , is my rotation not correct or how i can achieve this ???

any idea or help 😀
Static bodies are not supposed to change position or angle. Use a kinematic body, and SetAngularVelocity instead of setting the angle directly with SetTransform.
@irresistible force thanks for reply,,
Actually i agree with you about that i must set the type of the body kinematic, BUT i try to use SetAngularVelocity as you said, the body will rotate about his origin and i need the body to rotate about the screen center

what you suggest ??
You can offset the fixture from the origin. Set the bodyDef position as the center of the screen, and the fixture at for example polygonShape.SetAsBox( 1,1, b2Vec2(0,5), 0);
@irresistible force thaks alot ,yes it work but i have a addtional question
i need the rotation just with 90 degree (i.e i do not need it rotate infinitly )do you know how can i do this ,

and do you know how can i put a mrak on your anwser to be the correct anwser for my question? 😀 😀
You can use GetAngle() to check the current rotation and set the velocity to zero when it has gone far enough.
@irresistible force thanks a lot , every thing you say work perfectly .
your answer is the correct answer thanks.
@irresistible force

You said before that "You can offset the fixture from the origin. Set the bodyDef position as the center of the screen, and the fixture at for example polygonShape.SetAsBox( 1,1, b2Vec2(0,5), 0);" and this is nice and correct,,
BUT what about if i need to use
myShape.SetAsEdge() method ...i.e if i really need to create a box use this method to give me an ability to add objects inside this box...how can i offset this box to for example b2Vec2(0,5) and in the same time i need to put his center to the screen center to to rotate about the origin ??
It's the same as for the solid box.

If your box is normally centered around the origin, it's vertices might be eg. anti-clockwise (-1,-1) (1,-1) (1,1) (-1,1), so these are what you'd give to SetAsEdge to create fixtures.

To offset it so that the box center is 5 units to the right of the body origin, just add 5 to the x values to get (4,-1) (6,-1) (6,1) (4,1).
@irresistible force thanks for replay..

yes ,the things you say is correct thanks again ,BUT i have an additional question related about what you suggested before , you said that "You can use GetAngle() to check the current rotation and set the velocity to zero when it has gone far enough."

Nowi notice some issue , i notes that it dose not stop in the angle 90 i made some print for the value for GetAngle() and notice that the angle jump on the 90 angle (i.e i change the stop angle to 91 and it work but why on the angle 90 it dose not stop OR to be more specific the 90 dose not consider from the printed list)

what you suggest??

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