I'm working on a project where I need to connect bodies at arbitrary locations with a prismatic joint. I'd do it with a distance joint, but the length will adjust over time. I'm guessing it would be easier to occasionally myPrismaticJoint.SetLimits(newLower,newUpper) than destroy and recreate large numbers of distance joints repeatedly.
If I understand the prismatic joint correctly, creating one looks something like this:

What I am attempting is more like this:

Getting the axis is the question. Straight horizontal/vertical axes are easy:

The slope for arbitrary points is also easy. I'm guessing it needs to be reduced to a unit circle (?). This function seems to be correct:
The result is kind of jumpy, though restitution is low. What should always be a straight joint sometimes appears "bent". Occasionally objects will fly completely apart in all directions (from my experience with C, this phenomenon has been NaN issues, though this is all in AS3).
Just wondering if I have the right understanding of the above, which I will readily admit could be completely wrong. Did I miss some in-built function that's going to make my life easy street? 🙂
Working with Boris' v2.02 port/Flash CS4. Much thanks to Erin for Box2d and Boris for the AS3 port.
If I understand the prismatic joint correctly, creating one looks something like this:

What I am attempting is more like this:

Getting the axis is the question. Straight horizontal/vertical axes are easy:

The slope for arbitrary points is also easy. I'm guessing it needs to be reduced to a unit circle (?). This function seems to be correct:
Code:
public function getAxis(vecA:b2Vec2, vecB:b2Vec2):b2Vec2 {
var rise:Number = vecB.y - vecA.y;
var run:Number = vecB.x - vecA.x;
var slope:Number = rise/run;
var unitY:Number = Math.sin(Math.atan(slope));
var unitX:Number = Math.cos(Math.atan(slope));
return new b2Vec2(unitX,unitY);
}
var rise:Number = vecB.y - vecA.y;
var run:Number = vecB.x - vecA.x;
var slope:Number = rise/run;
var unitY:Number = Math.sin(Math.atan(slope));
var unitX:Number = Math.cos(Math.atan(slope));
return new b2Vec2(unitX,unitY);
}
The result is kind of jumpy, though restitution is low. What should always be a straight joint sometimes appears "bent". Occasionally objects will fly completely apart in all directions (from my experience with C, this phenomenon has been NaN issues, though this is all in AS3).
Just wondering if I have the right understanding of the above, which I will readily admit could be completely wrong. Did I miss some in-built function that's going to make my life easy street? 🙂
Working with Boris' v2.02 port/Flash CS4. Much thanks to Erin for Box2d and Boris for the AS3 port.




