Joint

Associated namespace: sm.joint

A userdata object representing a joint in the game.

Values:

Functions:

Operations:

OperationDescription
Joint == JointChecks if two instances of Joint refer to the same Joint.

angle number

Get:

Returns the angle of a bearing.


angularVelocity number

Get:

Returns the angular velocity of a bearing.

The angular velocity can be set using setMotorVelocity or setTargetAngle.


appliedImpulse number

Get:

Returns the applied impulse of a bearing.

The applied impulse can be set using setMotorVelocity or setTargetAngle.


color Color

Get:

Returns the color of a joint.

Set:

Server only

Sets the color of a joint.


id integer

Get:

Returns the id of a joint.


length number

Get:

Returns the current length of a piston. The length is measured in blocks.


localPosition Vec3

Get:

Returns the local position of a joint.


localRotation Quat

Get:

Returns the local rotation of a joint.


reversed boolean

Get:

Returns whether a bearing has been reversed using the Connect Tool. A reversed bearing rotates counterclockwise.


shapeA Shape

Get:

Returns the Shape a joint is attached to. This shape does always exist.


shapeB Shape

Get:

Returns the Shape that is attached to a joint on another Body. This method returns nil if there is no shape attached to the joint.


type string

Get:

Returns the joint type of a joint.


uuid Uuid

Get:

Returns the uuid string unique to a joint type.


worldPosition Vec3

Get:

Returns the world position of a joint.


xAxis Vec3

Get:

Returns the local x-axis vector of a joint.


yAxis Vec3

Get:

Returns the local y-axis vector of a joint.


zAxis Vec3

Get:

Returns the local z-axis vector of a joint.


createBlock(joint, uuid, size, position, forceCreate=true)

Server only

Create a block on joint.

Parameters:

TypeNameDescription
JointjointThe parent joint.
UuiduuidThe uuid of the shape.
Vec3sizeThe shape's size.
Vec3positionThe shape's local position.
booleanforceCreate=trueSet true to force create the shape.

createPart(joint, uuid, position, zAxis, xAxis, forceCreate=true)

Server only

Create a part on joint.

Parameters:

TypeNameDescription
JointjointThe parent joint.
UuiduuidThe uuid of the shape.
Vec3positionThe shape's local position.
Vec3zAxisThe shape's local z direction.
Vec3xAxisThe shape's local x direction.
booleanforceCreate=trueSet true to force create the shape.

getAngle(bearing)

Returns the angle of a bearing.

Parameters:

TypeNameDescription
JointbearingThe bearing.

Returns:

TypeDescription
numberThe bearing's angle. The angle ranges between `-math.pi` and `+math.pi`.

getAngularVelocity(bearing)

Returns the angular velocity of a bearing.

The angular velocity can be set using setMotorVelocity or setTargetAngle.

Parameters:

TypeNameDescription
JointbearingThe bearing.

Returns:

TypeDescription
numberThe bearing's angular velocity.

getAppliedImpulse(bearing)

Returns the applied impulse of a bearing.

The applied impulse can be set using setMotorVelocity or setTargetAngle.

Parameters:

TypeNameDescription
JointbearingThe bearing.

Returns:

TypeDescription
numberThe bearing's applied impulse.

getBoundingBox(joint)

Returns the bounding box of a joint – the dimensions that a joint occupies when building.

Parameters:

TypeNameDescription
JointjointThe joint.

Returns:

TypeDescription
Vec3The size of the joint's bounding box.

getColor(joint)

Returns the color of a joint.

Parameters:

TypeNameDescription
JointjointThe joint.

Returns:

TypeDescription
ColorThe joint's color.

getId(joint)

Returns the id of a joint.

Parameters:

TypeNameDescription
JointjointThe joint.

Returns:

TypeDescription
integerThe joint's id.

getLength(piston)

Returns the current length of a piston. The length is measured in blocks.

Parameters:

TypeNameDescription
JointpistonThe piston.

Returns:

TypeDescription
numberThe piston's current length in blocks.

getLocalPosition(joint)

Returns the local position of a joint.

Parameters:

TypeNameDescription
JointjointThe joint.

Returns:

TypeDescription
Vec3The joint's local position.

getLocalRotation(joint)

Returns the local rotation of a joint.

Parameters:

TypeNameDescription
JointjointThe joint.

Returns:

TypeDescription
QuatThe joint's local rotation.

getShapeA(joint)

Returns the Shape a joint is attached to. This shape does always exist.

Parameters:

TypeNameDescription
JointjointThe joint.

Returns:

TypeDescription
ShapeThe joint's first shape.

getShapeB(joint)

Returns the Shape that is attached to a joint on another Body. This method returns nil if there is no shape attached to the joint.

Parameters:

TypeNameDescription
JointjointThe joint.

Returns:

TypeDescription
ShapeThe joint's second shape.

getShapeUuid(joint)

Returns the uuid string unique to a joint type.

Parameters:

TypeNameDescription
JointjointThe joint.

Returns:

TypeDescription
UuidThe joint's uuid.

getSticky(joint)

Returns the sticky directions of the joint for positive xyz and negative xyz.

A value of 1 means that the direction is sticky and a value of 0 means that the direction is not sticky.

Parameters:

TypeNameDescription
JointjointThe joint.

Returns:

TypeDescription
Vec3,Vec3The negative xyz sticky and the positive xyz sticky.

getType(joint)

Returns the joint type of a joint.

Parameters:

TypeNameDescription
JointjointThe joint.

Returns:

TypeDescription
stringOne of the joint's type found in (sm.joint.types).

getWorldPosition(joint)

Returns the world position of a joint.

Parameters:

TypeNameDescription
JointjointThe joint.

Returns:

TypeDescription
Vec3The joint's world position.

getWorldRotation(joint)

Returns the world rotation of a joint.

Parameters:

TypeNameDescription
JointjointThe joint.

Returns:

TypeDescription
QuatThe joint's world rotation.

getXAxis(joint)

Returns the local x-axis vector of a joint.

Parameters:

TypeNameDescription
JointjointThe joint.

Returns:

TypeDescription
Vec3The joint's x-axis.

getYAxis(joint)

Returns the local y-axis vector of a joint.

Parameters:

TypeNameDescription
JointjointThe joint.

Returns:

TypeDescription
Vec3The joint's y-axis.

getZAxis(joint)

Returns the local z-axis vector of a joint.

Parameters:

TypeNameDescription
JointjointThe joint.

Returns:

TypeDescription
Vec3The joint's z-axis.

isReversed(bearing)

Returns whether a bearing has been reversed using the Connect Tool. A reversed bearing rotates counterclockwise.

Parameters:

TypeNameDescription
JointbearingThe bearing.

Returns:

TypeDescription
booleanWhether the bearing is reversed (rotating counterclockwise).

setColor(joint, color)

Server only

Sets the color of a joint.

Parameters:

TypeNameDescription
JointjointThe joint.
ColorcolorThe new color.

setMotorVelocity(bearing, targetVelocity, maxImpulse)

Sets the motor velocity for a bearing. The bearing will try to maintain the target velocity with the given amount of impulse/strength.

In Scrap Mechanic, the Gas Engine increases both velocity and impulse with every gear. The Electric Engine increases velocity, but maintains the same impulse for every gear, making it sturdier.

This method cancels the effects of setTargetAngle.

Parameters:

TypeNameDescription
JointbearingThe bearing.
numbertargetVelocityThe target velocity.
numbermaxImpulseThe max impulse.

setTargetAngle(bearing, targetAngle, targetVelocity, maxImpulse)

Sets the target angle for a bearing. The bearing will try to reach the target angle with the target velocity and the given amount of impulse/strength.

The target angle is set to range between `-math.pi` and `+math.pi`. The bearing will always try to rotate in the direction closest to the target angle.

This method cancels the effects of setMotorVelocity.

Parameters:

TypeNameDescription
JointbearingThe bearing.
numbertargetAngleThe target angle.
numbertargetVelocityThe target velocity.
numbermaxImpulseThe max impulse.

setTargetLength(bearing, targetLength, targetVelocity, maxImpulse=100000)

Server only

Sets the target length for a piston. The piston will try to reach the target length with the target velocity and the given amount of impulse/strength.

The target length is measured in blocks.

This method cancels the effects of setMotorVelocity.

Parameters:

TypeNameDescription
JointbearingThe bearing.
numbertargetLengthThe target length.
numbertargetVelocityThe target velocity.
numbermaxImpulse=100000The max impulse. (Defaults to impulse used in game)