Just figured out how to hack the Prismatic Joint into a spring:
You'll have to do that for each time step. I see a lot of people asking about Springs here so I thought I'd post it.
Code:
var pj:b2PrismaticJoint = joint as b2PrismaticJoint;
var pjt:Number = pj.GetJointTranslation();
var pjs:Number = pj.GetJointSpeed();
pj.SetMaxMotorForce(Math.abs((pjt * 100) + (pjs * 10))); // 100 is the spring constant, 10 is the damping constant.
pj.SetMotorSpeed(pjt > 0 ? -10000 : +10000); // Arbitrary humongous number.
var pjt:Number = pj.GetJointTranslation();
var pjs:Number = pj.GetJointSpeed();
pj.SetMaxMotorForce(Math.abs((pjt * 100) + (pjs * 10))); // 100 is the spring constant, 10 is the damping constant.
pj.SetMotorSpeed(pjt > 0 ? -10000 : +10000); // Arbitrary humongous number.
You'll have to do that for each time step. I see a lot of people asking about Springs here so I thought I'd post it.