Box2D Forums

It is currently Thu May 23, 2013 3:48 pm

All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: How to pin daynamic body
PostPosted: Sun Jun 12, 2011 10:55 am 
Offline

Joined: Mon Jun 06, 2011 2:23 am
Posts: 20
Hi all...

I have a small question today...
i need to know how can i pin a dynamic body in specific position ?

(and if it applicable too) how can i pin a dynamic body with kinematic body in some position?

any suggestion ? :D


Top
 Profile  
 
PostPosted: Sun Jun 12, 2011 11:21 am 
Offline

Joined: Tue Jan 18, 2011 3:27 pm
Posts: 38
What do you mean by "pin"? If you just want it to rotate in place use a revolute joint:

Code:
b2RevoluteJointDef rjd;
rjd.Initialize(ground, body, b2Vec2(1.0f, 1.0f));
world->CreateJoint(&rjd);

ground is a static body.

If you also don't want it to rotate you should also use rjd.enableLimit = true;

If you don't want the body to interact with other bodies (i.e. bodies will pass through it), use body->SetActive(false);

If you want the body to stay in place until another body collides with it use body->SetAwake(false);


Top
 Profile  
 
PostPosted: Sun Jun 12, 2011 11:27 am 
Offline

Joined: Mon Jun 06, 2011 2:23 am
Posts: 20

i need the dynamic body pin or "stick" when it collide with kinematic body


do you suggest any thing else?


Top
 Profile  
 
PostPosted: Mon Jun 13, 2011 12:06 am 
Offline

Joined: Tue Jan 18, 2011 3:27 pm
Posts: 38
Then maybe you need to connect your body with the kinematic body using a weld joint once they hit each other:
Code:
      b2WeldJointDef wjd;
      wjd.Initialize(body1, body2, b2Vec2(0,0));
      world->CreateJoint(&wjd);


Top
 Profile  
 
PostPosted: Mon Jun 13, 2011 1:31 am 
Offline

Joined: Mon Jun 06, 2011 2:23 am
Posts: 20
hayy...
every time when i try co make a joint inside b2ContactListener, the app stop (crash) and the debugger take me to this lines,,,

Code:
b2Joint* b2World::CreateJoint(const b2JointDef* def)
{
   b2Assert(IsLocked() == false);
   if (IsLocked())
   {
      return NULL;
   }



is it applicable that i create a joint to tie a dynamic body with kinematic when they collide ????
i need to know if this true logically ??


Top
 Profile  
 
PostPosted: Mon Jun 13, 2011 3:35 am 
Offline

Joined: Tue Jan 18, 2011 3:27 pm
Posts: 38
I guess you can't create joints while Box2D checks for collisions. Instead, maybe you can keep all collisions in an array and then iterate through all of them in your tick() method, creating the joints as necessary.

There's a tutorial which explains how to store collisions in an array: http://www.raywenderlich.com/505/how-to ... al-part-22


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

All times are UTC - 8 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 0 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