Prismatic joint between two arbitrarily placed bodies

Quote:
You had several errors. The worst was setting the polygon position to the body world positions. You didn't do this for the circles, so why do it for the boxes? Anyhow, shapes are defined relative to the parent body. Shapes have no transform of their own.
I used a different order in setting it up (bodyDef,shapeDef vs. shapeDef,bodyDef), plus the Polygon uses SetAsOrientedBox which a Circle has no need for. Which is probably why the version with a Circle as the end point of the joint gave me no problems while the Polygon was completely confused. This is fixed now:
Code:
// create pivotA to attach to the first body
var pAshapedef:b2PolygonDef = new b2PolygonDef();
pAshapedef.density     = 1.0;
pAshapedef.friction    = 0.9;
pAshapedef.restitution = 0.5;
pAshapedef.SetAsOrientedBox(25/m_physScale, 3/m_physScale, new b2Vec2(0,0), Math.atan(slopeAB));
// etc.

The "100/m_physScale + 2", etc for the initial body locations is an odd formulation but it was just to keep the example in tune with the illustrations above. I probably should have converted it to one or the other units. The result is meters anyhow.

Further, the function to make the joint will only know the two bodies it has to work with. All coordinates have to be pulled from there. Hmmm... I guess I took the function in my first .zip and made it inline in the PhysTest version, so that wouldn't be clear.

Quote:
Also, you are creating these light weight intermediate bodies that reduce stability. See the limitations section of the manual: http://box2d.org/manual.html#_Toc258082979

Good point. I hadn't gotten into tweaking those variables. It should also be said there will not be gravity in the final version (at least, no gravity as a world vector).

Quote:
Finally, it is really confusing what you are trying to achieve. Do you really want your circles not to rotate?

Yes, I need the circles to keep their orientation the same regardless of how they are positioned with respect to each other. They need to be kept at a specified distance while being free to move otherwise.

But the distance will change. I'm guessing that modifying the translation limits of a prismatic joint is less expensive than destroying and recreating a distance joint. I have no idea if I would additionally need to reposition the bodies with respect to each other to form the distance joint at the proper distance. That and more so if there are lots of these joints to modify. Then again, is having a motor continually pushing on it worse? I don't know. But I can set the motor and forget about it.

This is it working pretty much as I want. Full code here.

Quote:
Did you see the post by pTymN where he was able to dynamically change the length of a distance joint? You can do this if you use softness as shown in the Web example. Perhaps you need a new joint type.
This one?: b2PrismaticJoint that doesn't stop rotation

Here's my config for the distance and lower/upper translation limits:
Code:
// create a prismatic joint between the two pivots
var prismaticABjdef:b2PrismaticJointDef = new b2PrismaticJointDef();

// get the axis from bodyA (or is this from bodyB ?)
var axis:b2Vec2 = b2Math.SubtractVV(bodyB.GetPosition(),bodyA.GetPosition());
axis.Normalize();

// this seems to be the correct point to initialize with:
var pBbodyX:Number = bodyB.GetPosition().x - axis.x;
var pBbodyY:Number = bodyB.GetPosition().y - axis.y;

prismaticABjdef.Initialize(pAbody, pBbody, new b2Vec2(pBbodyX,pBbodyY), axis);

var distanceAB:Number = b2Math.b2Distance(bodyA.GetPosition(),bodyB.GetPosition());

// limits allow the joint to grow or shrink
prismaticABjdef.enableLimit      = true;

// this lowerTranslation == the distance between the bodies (px to m)
//   minus the radius of each body, only it is negative because the start
//   is on body B instead of A where I thought it was going to be...
// which would make it easier for me to keep the math straight when I alter it later:

prismaticABjdef.lowerTranslation = (25/m_physScale * 2) - distanceAB;
prismaticABjdef.upperTranslation = 0.0; // - 25/m_physScale; 
         
// motors cause the joint to push to its full extension:
prismaticABjdef.enableMotor      = true;
prismaticABjdef.maxMotorForce    = 100;
prismaticABjdef.motorSpeed       = 4.0;

var prismaticABjoint:b2PrismaticJoint = m_world.CreateJoint(prismaticABjdef) as b2PrismaticJoint;

I admit it could be done other ways. But I haven't learned them all yet. That's why I've been reading up on tutorials and documentation and of course started asking questions here when I hit a brick wall. More things are written for 2.02 so that's why I haven't dabbled with 2.1a + fixtures, etc. I don't really expect the forum to solve everything for me. Apologies for being such a noob. 😳
Here it is: http://www.box2d.org/forum/viewtopic.php?f=3&t=4257

This would let you get rid of the pivot bodies. Fixed rotation should still work.
Thanks for the update. I'll take a look.
Hot dog it works!

I guess I considered messing with the internal variables directly to be the wrong approach. But comparing 2.02 and 2.1a I see the latter's DistanceJoint has an explicit SetLength().

And the original bodies keep their non-rotating orientation - just what I need.

Thanks again!

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