Box2D Forums

It is currently Fri May 24, 2013 1:49 am

All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 13 posts ]  Go to page 1, 2  Next
Author Message
PostPosted: Mon Jun 06, 2011 2:30 am 
Offline

Joined: Mon Jun 06, 2011 2:23 am
Posts: 20
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:
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 :D


Top
 Profile  
 
PostPosted: Mon Jun 06, 2011 4:11 am 
Offline

Joined: Tue Jun 24, 2008 8:25 pm
Posts: 1517
Location: Tokyo
Static bodies are not supposed to change position or angle. Use a kinematic body, and SetAngularVelocity instead of setting the angle directly with SetTransform.


Top
 Profile  
 
PostPosted: Mon Jun 06, 2011 4:20 am 
Offline

Joined: Mon Jun 06, 2011 2:23 am
Posts: 20
@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 ??


Top
 Profile  
 
PostPosted: Mon Jun 06, 2011 4:59 am 
Offline

Joined: Tue Jun 24, 2008 8:25 pm
Posts: 1517
Location: Tokyo
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);


Top
 Profile  
 
PostPosted: Mon Jun 06, 2011 5:20 am 
Offline

Joined: Mon Jun 06, 2011 2:23 am
Posts: 20
@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? :D :D


Top
 Profile  
 
PostPosted: Mon Jun 06, 2011 6:47 am 
Offline

Joined: Tue Jun 24, 2008 8:25 pm
Posts: 1517
Location: Tokyo
You can use GetAngle() to check the current rotation and set the velocity to zero when it has gone far enough.


Top
 Profile  
 
PostPosted: Tue Jun 07, 2011 2:23 am 
Offline

Joined: Mon Jun 06, 2011 2:23 am
Posts: 20
@irresistible force thanks a lot , every thing you say work perfectly .
your answer is the correct answer thanks.


Top
 Profile  
 
PostPosted: Tue Jun 07, 2011 10:33 am 
Offline

Joined: Mon Jun 06, 2011 2:23 am
Posts: 20
@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 ??


Top
 Profile  
 
PostPosted: Tue Jun 07, 2011 10:58 am 
Offline

Joined: Tue Jun 24, 2008 8:25 pm
Posts: 1517
Location: Tokyo
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).


Top
 Profile  
 
PostPosted: Tue Jun 07, 2011 11:13 am 
Offline

Joined: Mon Jun 06, 2011 2:23 am
Posts: 20
@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??


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 13 posts ]  Go to page 1, 2  Next

All times are UTC - 8 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group