Prismatic joint is created by the createPrismaticJoint function and it has nine parameters. The paramters are as follows: bodies connected in the joint, anchor point, axis, reference angle, additional joint settings and flag which specifies whether bodies connected in the joint collide together.
Axis
The joint axis is a line where the bodies can move along. It is specified in the first body’s local coordinates, so you can think of it as direction setter from which the second body can move. The first body’s point of view.
Image: axis

Limit
The limit restricts the movement of the body along the axis. It can be set on two ends: bottom and upper limit. The limits are set in additional joint’s properties. Bodies and joint are created in _createBodies function
Example: _createBodies function – creates the bodies and joint
// create two bodies and connect it with the distance joint
function _createBodies()
{
// the body side
var bodySide = 80;
// first rectangle
this._rect1 = this.addPolygonBody(Bitmap.fromFile("app://rectangle.png"), #dynamic, 1.0, 0.1, 0.7, bodySide, bodySide);
// set body damping
this._rect1.setLinearDamping(0.5);
this._rect1.setAngularDamping(0.5);
// place the body
this._rect1.setPosition(System.width / 2, System.height / 2); // create the prismatic joint
// set limits
var jointDef = {
lowerTranslation : -3.0, /*meters*/
upperTranslation : 5.0, /*meters*/
enableLimit : true,
}
this._prismaticJoint = this.createPrismaticJoint(this._ground, this._rect1, System.width / 2, System.height / 2, 0.0, 1.0, 0.0, jointDef, true)
}
Motor
The joint has a motor, which moves the body along the axis. The motor has two important properties: motor speed and maximal motor force. If the motor speed is too small (smaller than gravity or other forces affecting the body) the motor would not be able to move the body.
Example: additional joint settings with motor allowed
// set joint
var jointDef = {
lowerTranslation : -3.0, /*meters*/
upperTranslation : 5.0, /*meters*/
enableLimit : true,
enableMotor : true,
motorSpeed : 1.0,
maxMotorForce : 100.0,
}
|