Building a Hinged Door

Roblox's physics system allows you to construct moving mechanisms like doors, rotating platforms, and even vehicles using constraints. For instance, a swinging door can be built using the HingeConstraint.

Door Setup

Start by creating parts for the door and its attachments. Attachments are where one object can connect to another. These attachments will later be used to connect the door to its frame with a hinge.

  1. Create two parts with names like Door and DoorFrame.

    alt

  2. Select DoorFrame. In the Properties, enable Anchored so it won't move.

    alt

  3. In the Explorer, hover over DoorFrame and add a new Attachment. Repeat the same to add an attachment to the Door.

    alt

  4. Rename the attachments to indicate what they're attached to, such as DoorAttachment and FrameAttachment.

    alt

Move the Attachments

New attachments are created in the center of a part. So they can work with the door, the two attachments need to be moved to face each other.

  1. To view constraints and attachments, in the Model tab, toggle on Constraint Details.

    alt

  2. In the Explorer, select FrameAttachment.

    alt

  3. Press F to focus on the attachment and zoom in if needed. Then, use the Move tool to position the attachment on the surface of the door frame, facing the door.

  4. Repeat the same to move DoorAttachment. Your attachments should be positioned on the surface facing their counterpart.

Left: FrameAttachment / Right: DoorAttachment

Rotate the Attachments

The orientation of an attachment affects how a constraint can move. For the door, both attachments must be rotated so the hinge swings left and right, like those on a standard door.

  1. On the door frame, hover over FrameAttachment. Notice the yellow arrow. This arrow, the axis, determines the hinge's rotation.

    alt

  2. For accurate rotation, turn on snapping in ModelSnap to Grid, and checking Rotate. Set the value to 90.

    alt

  3. Use the Rotate tool to orient both yellow attachments to point upwards. If your axes are already vertical, no action is needed.

    alt

Adding the Constraint

Remember, constraints are a way of connecting two attachments to move in a specific way. This door will use a HingeConstraint, a common constraint that rotates objects along the axes of two attachments.

  1. Under DoorFrame, create a new HingeConstraint.

    alt

  2. In the constraint's properties, find Attachment0. Click the empty box right of the property and then, in the Explorer, click DoorAttachment.

  3. Repeat the same process by connecting Attachment1 to FrameAttachment. The properties should appear as below.

    alt

  4. Test the project by walking into the door with your character.

Adjust the Door

The door is currently able to swing past the door frame. This can be fixed by adjusting the hinge limits.

  1. In the properties for HingeConstraint, find and toggle LimitsEnabled. When active, you can set the rotation limits of the hinge.

    alt

  2. To make sure this is oriented correctly, select DoorAttachment and use the rotate tool so the orange arrow points towards the door frame, like below.

    alt

  3. Under the Limits section of the properties, both LowerAngle and UpperAngle to -90 and 90, respectively. This creates a range of motion like the image on the left.

  4. Test the door and notice that the hinge is now limited.

With the door complete, take some time to explore using hinge constraints in different situations, such as a trap door or a swinging axe trap.