Box2D Forums

It is currently Mon May 20, 2013 10:58 am

All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: Wed Jun 27, 2012 3:51 am 
Offline

Joined: Mon Jun 28, 2010 2:33 am
Posts: 50
hello,

i am re-visiting box2d for a little game and while connecting two bodys to a revolute joint, i noticed that sometimes the attached body has a wrong initial rotation.
when not attached, or when the body is set to "b2_staticBody" the rotation is correct.

the first body has its "SetFixedRotation". flag set to true

is there something special to note with the revolute joints angle/rotation?

Thanks a bunch!


Top
 Profile  
 
PostPosted: Wed Jun 27, 2012 10:08 pm 
Offline

Joined: Sun Oct 25, 2009 3:28 am
Posts: 242
How are you creating the revolute joint? Are you using the Initialize helper function or are you setting the local anchors manually?

If you're setting the local anchors manually, make sure that the local anchors are ultimately in the same place in the world space. If the world positions of the local anchors are different, Box2D will adjust the bodies together until the anchors are in the same place.

If you're using the Initialize helper function, then...I'm not sure. x] There might be something else, like setting the transform, or setting the angle of the body, etc.


Top
 Profile  
 
PostPosted: Thu Jun 28, 2012 9:05 am 
Offline

Joined: Mon Jun 28, 2010 2:33 am
Posts: 50
hi and thanks for the answer.

i am using a self made joint builder method like this:
Code:
public static function makeRevoluteJoint(world:b2World,ref_angle:Number,body_1:b2Body,body_2:b2Body,anchor_1:b2Vec2,anchor_2:b2Vec2,motor:Boolean=false,limits:Array=null):b2RevoluteJoint{
   var jd:b2RevoluteJointDef = new b2RevoluteJointDef();

    jd.Initialize(body_1, body_2,new b2Vec2(0,0));
   jd.referenceAngle=ref_angle

    jd.localAnchorA=anchor_1
    jd.localAnchorB=anchor_2
   jd.enableMotor=motor;

   var revolute_joint:b2RevoluteJoint=world.CreateJoint(jd) as b2RevoluteJoint;
   if(limits!=null){
      revolute_joint.EnableLimit(true)
      revolute_joint.SetLimits(limits[0],limits[1]);
   }
    return revolute_joint
};

i call it using:
Code:
_joint=makeRevoluteJoint(_world,0,_firstbody,_secondbody,new b2Vec2(0,0),new b2Vec2(0,0))


i did not place the body on the anchor position in the world space.
maybe thats the problem?


Top
 Profile  
 
PostPosted: Fri Jun 29, 2012 12:22 am 
Offline

Joined: Sun Oct 25, 2009 3:28 am
Posts: 242
Hm, you don't need the jd.localAnchorA if you use the jd.Initialize(). That already sets the local anchors in the bodies in respect to the given world point. If both bodies aren't at the (0,0) world position and you set both local anchors at (0,0), then they'll move.


Top
 Profile  
 
PostPosted: Thu Jul 05, 2012 2:41 am 
Offline

Joined: Mon Jun 28, 2010 2:33 am
Posts: 50
Hello jayther,

thanks for the answer.
it put me in the right direction.
seems i did not understand the anchors completely.
now everything is rosy!

big ups!


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 8 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 5 guests


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