HingeConstraint
Lets one part turn around an axis through a pivot point: doors, wheels, fans and trapdoors.
- Inherits: Constraint → Instance
- Creatable: Yes:
new HingeConstraint(), orInstance.new('HingeConstraint', parent). - Replication: Replicated: clients get a copy, and changes the server makes reach them.
pivot0 and pivot1 are the same point seen from each part: where the joint attaches, relative
to each part’s center, in the part’s own (rotated) axes. For a door hinged on its left edge to a
post, pivot1 is the door’s left edge and pivot0 the matching point on the post. part1
turns around axis (in part0’s axes) through that point.
Angles are measured from the pose the parts are in when the hinge is created. Hinged parts don’t collide with each other, so a door can overlap its frame.
Properties
Section titled “Properties”pivot0
Section titled “pivot0”Type: Vector3 · Default: new Vector3(0, 0, 0) · Access: read/write · Replicates: yes
Where the joint attaches to part0, relative to its center (in the part’s own axes).
pivot1
Section titled “pivot1”Type: Vector3 · Default: new Vector3(0, 0, 0) · Access: read/write · Replicates: yes
Where the joint attaches to part1, relative to its center (in the part’s own axes).
Type: Vector3 · Default: new Vector3(0, 1, 0) · Access: read/write · Replicates: yes
Turning axis in part0’s own axes ((0, 1, 0) is a door; 2D games always use Z).
motorEnabled
Section titled “motorEnabled”Type: boolean · Default: false · Access: read/write · Replicates: yes
Drive the hinge at angularVelocity.
angularVelocity
Section titled “angularVelocity”Type: number · Default: 0 · Range: -1,000 to 1,000 (clamped) · Access: read/write · Replicates: yes
Motor speed in radians per second (positive turns counter-clockwise around axis).
motorMaxTorque
Section titled “motorMaxTorque”Type: number · Default: 100000 · Range: 0 to 1,000,000,000 (clamped) · Access: read/write · Replicates: yes
Strongest twist the motor applies.
limitsEnabled
Section titled “limitsEnabled”Type: boolean · Default: false · Access: read/write · Replicates: yes
Keep the angle between lowerAngle and upperAngle.
lowerAngle
Section titled “lowerAngle”Type: number · Default: -90 · Range: -180 to 180 (clamped) · Access: read/write · Replicates: yes
Degrees, from the pose when the hinge was created.
upperAngle
Section titled “upperAngle”Type: number · Default: 90 · Range: -180 to 180 (clamped) · Access: read/write · Replicates: yes
Degrees, from the pose when the hinge was created.
Inherited from Constraint: part0, part1, enabled
Inherited from Instance: name, archivable, id, className, parent, destroyed
Methods
Section titled “Methods”Inherited from Instance: getPropertyChangedSignal, setAttribute, getAttribute, getAttributes, getAttributeChangedSignal, getChildren, getDescendants, findFirstChild, findFirstChildOfClass, findFirstChildWhichIsA, findFirstAncestor, findFirstAncestorWhichIsA, waitForChild, isA, isDescendantOf, isAncestorOf, getFullName, clearAllChildren, destroy, clone, toString
Events
Section titled “Events”Inherited from Instance: changed, childAdded, childRemoved, descendantAdded, descendantRemoving, ancestryChanged, destroying, attributeChanged
Examples
Section titled “Examples”A door and a fan
Section titled “A door and a fan”import { HingeConstraint, Part, Vector3, getChild, workspace } from '@rally/sdk';
const post = getChild(workspace, 'Post', Part); // anchoredconst door = getChild(workspace, 'Door', Part); // 4 wide, anchored = false
const hinge = new HingeConstraint();hinge.part0 = post;hinge.part1 = door;hinge.pivot0 = new Vector3(0.5, 0, 0); // the post's right facehinge.pivot1 = new Vector3(-2, 0, 0); // the door's left edgehinge.axis = new Vector3(0, 1, 0); // turn around Yhinge.limitsEnabled = true; // swing between -90 and 90 degreeshinge.parent = door;
// A motorized fan: spins at 6 radians per second.const fan = new HingeConstraint();fan.part0 = getChild(workspace, 'FanBase', Part);fan.part1 = getChild(workspace, 'FanBlades', Part); // anchored = falsefan.axis = new Vector3(0, 0, 1);fan.motorEnabled = true;fan.angularVelocity = 6;fan.motorMaxTorque = 1e6; // how hard it may push to keep that speedfan.parent = workspace;