Skip to main content

Hinge Rotator

NAMESPACEMyDreamGameStudio.InteractAnything
MENU PATHInteraction System > Utilities > Hinge Rotator
COMPATIBILITYUnity 6.0+
DOC VERSION

An event-driven utility component that rotates a transform around a single locked local axis. It clamps rotation to a specific min/max range and supports optional "locked" snap angles (detents).

This is not an interactor itself; it is a mechanical driver. You attach this alongside an Interactable and wire the interactable's output events directly to the rotator's public methods to create doors, levers, dials, and wheels.


Editor Interface​

HINGE ROTATORANGULAR MOTIONDOORS / DIALSRotates an object around a locked local axis with angle limits, detent snaps, and path waypoints.TARGET & AXIS SETUP✦ Sync Zero RefHinge TargetNone (Transform)Rotation AxisX0Y1Z0Min Angle (°)0Max Angle (°)90TOGGLE ROTATION DYNAMICSOpen Angle (°)90Closed Angle (°)0Rotate Speed (°/s)180DRAG ROTATION DYNAMICSDrag Mouse AxisMouse XDrag Sensitivity0.3Drag Speed Limit (°/s)720SCENE GIZMOS & PREVIEWGizmos (Editor Only — never affects runtime behavior)Show GizmosShow Ghost PreviewsPreview Angle (0-1)PATH EVENTS (optional)Angle Waypoints0List is empty+-

Configuration Variables​

Target & Range​

Hinge Target
TransformDef: Self
The object that actually rotates. If left empty, it defaults to the transform this component is directly attached to.
Rotation Axis
Vector3Def: (0,1,0)
The single local axis that rotation is locked to. (0,1,0) spins around the Y-axis (like a standard door), while (1,0,0) spins around X (like an oven door).
Min / Max Angle
float
The absolute hard limits for the rotation, measured in degrees from the zero-reference pose. The object will never rotate past these points.

Toggle Dynamics (On / Off)​

Open / Closed Angle
float
The specific target degrees the hinge aims for when RotateToOpen() or RotateToClose() are called.
Rotate Speed (°/s)
floatDef: 180.0
The maximum degrees per second the hinge will rotate while animating automatically to the Open or Closed positions.

Drag Dynamics (Continuous Input)​

Drag Mouse Axis
EnumDef: Mouse X
Determines if horizontal (X) or vertical (Y) mouse movement drives the rotation. Use X for doors and Y for levers.
Drag Sensitivity
floatDef: 0.3
Degrees of rotation applied per unit of raw mouse delta. If dragging feels physically reversed, do not use negative numbers here; flip the 'Invert Drag' toggle on the attached Interactable component instead.
Drag Speed Limit (°/s)
floatDef: 720.0
Caps how fast the object can move toward the drag target per second. This prevents heavy visual snapping if the player violently jerks the mouse.

Advanced Features​

Locked Angles
float[]
Specific angles the hinge will 'snap' to if released nearby. Requires wiring SnapToNearestLockedAngle() to the OnInteractionComplete event.
Angle Waypoints
AnglePathEvent
Fires a UnityEvent whenever the current angle passes a specific degree point. Perfect for triggering a click sound every time a combination dial ticks past a number, regardless of how fast it is spinning.

Editor Gizmos & Previewing​

The HingeRotator features heavy Scene-view integration to make setup visual rather than mathematical.

Min / Closed (0°)Max / Open (90°)

WAYPOINT EVENT

LIVE PREVIEW

At the bottom of the inspector, you will find the Preview Angle (0-1) scrubber. In Edit Mode (not just Play mode), dragging this slider will physically rotate the model in your Scene view so you can verify your Min, Max, Open, and Closed states exactly as they will look in-game.

When the object is selected in the Scene View, a custom magenta rotation arc is drawn matching your Min/Max bounds, along with ghost-mesh previews of where the object will end up at its extremes. If you configure Angle Waypoints, they will visually appear as markers on the rotation arc.


Wiring Up Interaction Types​

Because this is a pure mechanical utility, you must wire the core Interactable events to this script's public methods.

Toggle (Doors, Latches)​

For an object that flips between two states:

  1. Set the Interactable type to Toggle.
  2. Wire OnToggleOn to HingeRotator.RotateToOpen().
  3. Wire OnToggleOff to HingeRotator.RotateToClose().
  4. Ensure your Rotate Speed (°/s) is set high enough so the door doesn't feel sluggish.

Drag (Heavy Valves, Free-swinging Doors)​

For an object the player must hold and manually swing:

  1. Set the Interactable type to Drag.
  2. Wire OnDragDelta to HingeRotator.RotateByDragDelta(Vector2). The Unity Event signatures match perfectly, so no adapter is needed.
  3. Set your Drag Mouse Axis to Mouse X for horizontal swings (doors) or Mouse Y for vertical pulls (levers).
  4. If you want the door to snap into a lock groove when let go, enable Use Locked Angles on the Rotator and wire the Interactable's OnInteractionComplete to SnapToNearestLockedAngle().

Push/Pull (Joysticks, Steering Wheels)​

For an object that returns to a specific point when released:

  1. Set the Interactable type to Push/Pull (and set its min/max to 0 and 1).
  2. Wire OnValueChanged to HingeRotator.SetAngle01(float). The float value will directly interpolate the hinge between its Min Angle and Max Angle instantly (since Push/Pull handles its own input smoothing).

The Zero Reference System​

During Awake(), or when Sync Zero Ref is clicked in the Inspector, the Rotator captures its current local rotation and permanently freezes it as "0 degrees". All subsequent Min, Max, Open, and Closed angles are measured relatively from this starting snapshot.

If you reposition a door frame in the scene and the door is now physically open by default, simply click the Sync Zero Ref button at the top of the Inspector to bake the new pose as the zero-baseline.