Pretty embarrassing to ask this since I've been using Box2D for years and had nearly the exact same code working in other ports of Box2D.
All my prismatic joints just don't work. The actor moves freely in all directions as if the joint weren't there, but when I use debug draw and value inspection, the values and resulting drawing makes sense, so I don't know what's going on.
The actor is dynamic, has density/mass > 0, is a box, 0 friction and restitution. Revolute joints work fine, so it's just the prismatic ones that don't.
My usage of the following is:
createSlidingJoint(body, null, new V2(1, 0));
(The null will default the second actor to the world's ground body)
All my prismatic joints just don't work. The actor moves freely in all directions as if the joint weren't there, but when I use debug draw and value inspection, the values and resulting drawing makes sense, so I don't know what's going on.
The actor is dynamic, has density/mass > 0, is a box, 0 friction and restitution. Revolute joints work fine, so it's just the prismatic ones that don't.
My usage of the following is:
createSlidingJoint(body, null, new V2(1, 0));
(The null will default the second actor to the world's ground body)
Code:
public function createSlidingJoint
(
one:b2Body,
two:b2Body = null,
dir:V2 = null,
jointID:int = -1,
collide:Boolean = false,
limit:Boolean = false,
motor:Boolean = false,
lower:Number = 0,
upper:Number = 0,
force:Number = 0,
speed:Number = 0
):b2PrismaticJoint
{
if(two == null)
{
two = world.m_groundBody;
}
if(dir == null)
{
dir = new V2(1, 0);
}
dir.normalize();
var pt1:V2 = one.GetWorldCenter();
//var pt2:V2 = two.GetWorldCenter();
var pjd:b2PrismaticJointDef = new b2PrismaticJointDef();
pjd.Initialize(one, two, pt1, dir);
pjd.collideConnected = collide;
pjd.enableLimit = limit;
pjd.enableMotor = motor;
pjd.lowerTranslation = toPhysicalUnits(lower);
pjd.upperTranslation = toPhysicalUnits(upper);
pjd.maxMotorForce = force;
pjd.motorSpeed = toPhysicalUnits(speed);
return world.CreateJoint(pjd) as b2PrismaticJoint;
}
(
one:b2Body,
two:b2Body = null,
dir:V2 = null,
jointID:int = -1,
collide:Boolean = false,
limit:Boolean = false,
motor:Boolean = false,
lower:Number = 0,
upper:Number = 0,
force:Number = 0,
speed:Number = 0
):b2PrismaticJoint
{
if(two == null)
{
two = world.m_groundBody;
}
if(dir == null)
{
dir = new V2(1, 0);
}
dir.normalize();
var pt1:V2 = one.GetWorldCenter();
//var pt2:V2 = two.GetWorldCenter();
var pjd:b2PrismaticJointDef = new b2PrismaticJointDef();
pjd.Initialize(one, two, pt1, dir);
pjd.collideConnected = collide;
pjd.enableLimit = limit;
pjd.enableMotor = motor;
pjd.lowerTranslation = toPhysicalUnits(lower);
pjd.upperTranslation = toPhysicalUnits(upper);
pjd.maxMotorForce = force;
pjd.motorSpeed = toPhysicalUnits(speed);
return world.CreateJoint(pjd) as b2PrismaticJoint;
}