How to pin daynamic body

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 ? 😀
What do you mean by "pin"? If you just want it to rotate in place use a revolute joint:

Code: Select all

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);

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


do you suggest any thing else?
Then maybe you need to connect your body with the kinematic body using a weld joint once they hit each other:

Code: Select all

      b2WeldJointDef wjd;
      wjd.Initialize(body1, body2, b2Vec2(0,0));
      world->CreateJoint(&wjd);
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: Select all

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 ??
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

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