Class · inherits ClickDetector
DragDetector
Instance which facilitates and encourages interaction with 3D objects in an experience.
About DragDetector
The DragDetector instance facilitates and encourages interaction with
3D objects in an experience, such as opening doors and drawers, sliding a part
around, and much more. Key features include:
Place a
DragDetectorunder anyBasePartorModelto make it draggable via all inputs (mouse, touch, gamepad, and VR), all without a single line of code.Choose from several
DragStyleoptions, define how the object responds to motion viaResponseStyle, and optionally apply axis or movement limits.Scripts can respond to manipulation of dragged objects to drive UI or make logical decisions, such as adjusting the light level in a room based on a sliding wall switch dimmer.
Players can manipulate anchored parts or models and they'll stay exactly where you put them upon release.
DragDetectorswork in Studio as long as you're not using the Select, Move, Scale, or Rotate tools, making it easier to test and adjust draggable objects while editing.
See the 3D Drag Detectors guide for details and usage examples.
Properties 27
ActivatedCursorIcon
: ContentIdSets the cursor icon to display when the mouse is activated over the parent of thisDragDetector.Sets the cursor icon to display when the mouse is activated over the parent of this
DragDetector. If this property is left blank, the detector will use the default icon.To change the activated cursor icon, set this property to the asset ID of the image you'd like to use.
ActivatedCursorIconContent
: ContentSets the cursor icon to display when the mouse is activated over the parent of thisDragDetector. Only supports asset URIsSets the cursor icon to display when the mouse is activated over the parent of this
DragDetector. If this property is left blank, the detector will use the default icon.To change the activated cursor icon, set this property to the asset ID of the image you'd like to use. Only asset URIs are supported for this property.
ApplyAtCenterOfMass
: booleanWhether constraint force is applied to the object's center of mass.When false (default), constraint force is applied at the point the user clicks on. When true, force is applied at the object's center of mass. Only relevant if
ResponseStyleisDragDetectorResponseStyle.Physicaland the parent object is unanchored.Axis
: Vector3NotReplicatedThe primary axis of motion, expressed relative to the reference frame.The primary axis of motion, expressed relative to the reference frame. For a
DragStyleofDragDetectorDragStyle.TranslateLine, the direction of translation; forDragDetectorDragStyle.TranslatePlane, the normal to the plane of motion; forDragDetectorDragStyle.RotateAxis, the axis of 1D rotation. Changing this value automatically updatesOrientationand vice versa.DragFrame
: CFrameTheCFrameof the pivot, dependent on the drag detector'sReferenceInstance.If
ReferenceInstanceis set, theCFrameof the pivot relative to the reference frame; otherwise, theCFrameof the pivot relative to its frame at the beginning of the drag.DragStyle
: DragDetectorDragStyleThe paradigm used to generate proposed motion.The paradigm used to generate proposed motion, given a stream of cursor rays. See
DragDetectorDragStylefor options.Enabled
: booleanWhether theDragDetectorresponds to user input.If true, the
DragDetectorresponds to user input; if false, it does not.MaxDragAngle
: floatAlong withMinDragAngle, impedes the drag detector's attempts to generate motion.If this is greater than
MinDragAngle, translation will be clamped within that range.This is not a constraint; it merely impedes the drag detector's attempts to generate motion in order to remain within limits. See
AddConstraintFunction()to add custom constraint to a drag.Only relevant if
DragStyleisDragDetectorDragStyle.RotateAxis.MaxDragTranslation
: Vector3Along withMinDragTranslation, impedes the drag detector's attempts to generate motion.In any dimension, if this is greater than
MinDragTranslation, translation will be clamped within that range.This is not a constraint; it merely impedes the drag detector's attempts to generate motion in order to remain within limits. See
AddConstraintFunction()to add custom constraint to a drag.MaxForce
: floatMaximum force applied for the object to reach its goal.Maximum force applied for the object to reach its goal. Only relevant if
ResponseStyleisDragDetectorResponseStyle.Physicaland the parent object is unanchored.MaxTorque
: floatMaximum torque applied for the object to reach its goal.Maximum torque applied for the object to reach its goal. Only relevant if
ResponseStyleisDragDetectorResponseStyle.Physicaland the parent object is unanchored.MinDragAngle
: floatAlong withMaxDragAngle, impedes the drag detector's attempts to generate motion.If this is less than
MaxDragAngle, translation will be clamped within that range.This is not a constraint; it merely impedes the drag detector's attempts to generate motion in order to remain within limits. See
AddConstraintFunction()to add custom constraint to a drag.Only relevant if
DragStyleisDragDetectorDragStyle.RotateAxis.MinDragTranslation
: Vector3Along withMaxDragTranslation, impedes the drag detector's attempts to generate motion.In any dimension, if this is less than
MaxDragTranslation, translation will be clamped within that range.This is not a constraint; it merely impedes the drag detector's attempts to generate motion in order to remain within limits. See
AddConstraintFunction()to add custom constraint to a drag.Orientation
: Vector3Specifies the YXZ rotation of axes of motion relative to the reference frame.Specifies the YXZ rotation of axes of motion relative to the reference frame (does not change the orientation of the reference frame itself). Linear translation and axial rotation will be on this reoriented Y axis, and planar translation in the XZ plane. Changing this value automatically updates
Axisand vice versa.PermissionPolicy
: DragDetectorPermissionPolicyControls the permission level for which players can interact with theDragDetector.Controls the permission level for which players can interact with the
DragDetector. Default isDragDetectorPermissionPolicy.Everybody.ReferenceInstance
: InstanceAn instance whoseCFrameis the reference frame for the drag detector.An instance whose
CFrameis the reference frame for the drag detector. TheDragFrameis expressed relative to thisCFramewhich may be retrieved via theGetReferenceFrame()method.If this instance is a
PVInstance, the reference frame will be its pivot; if anAttachment, then its worldCFrame. If it isnilor neither of the former, the reference frame will be based on the pivot of the drag detector's parentBasePartorModel.ResponseStyle
: DragDetectorResponseStyleThe paradigm used to move, or not move, the objects affected by the drag detector.Once the proposed motion has been computed and potentially constrained, this is the paradigm used to move, or not move, the objects affected by the
DragDetector. SeeDragDetectorResponseStylefor options.Responsiveness
: floatHigher values cause the object to reach its goal more rapidly.Higher values cause the object to reach its goal more rapidly. Only relevant if
ResponseStyleisDragDetectorResponseStyle.Physicaland the parent object is unanchored.RunLocally
: booleanWhether user input on aDragDetectorreplicates to the server or remains local to the specific client.If false (default), the client sends replicated signals (
DragStart,DragContinue,DragEnd) to the server which processes cursor rays, makes changes to the data model, and replicates them onwards to clients.If true, the client processes those signals itself and does not replicate them to the server. Client
LocalScriptsmay be used to respond to these events andRemoteEventsmay be used to send any resulting changes that should be replicated to the server.SecondaryAxis
: Vector3NotReplicatedThe secondary axis of the motion.The secondary axis of the motion. Relates to orientation using the same paradigm as
Attachments.TrackballRadialPullFactor
: floatIfDragStyleisDragDetectorDragStyle.RotateTrackball, multiplier for adding a radial pull rotation as a contribution to the total.When the cursor is outside the trackball, the
DragDetectorcan apply a radial pull rotation that turns the ball as if it were trying to roll out toward the cursor. This property is a 0 to 1 multiplier for adding that rotation as a contribution to the total. Only relevant ifDragStyleisDragDetectorDragStyle.RotateTrackball.TrackballRollFactor
: floatIfDragStyleisDragDetectorDragStyle.RotateTrackball, multiplier for adding roll rotation to the total.When the cursor is outside the trackball, the
DragDetectorcan apply a roll rotation that turns the ball as if it were mounted on a vinyl record facing the viewer. This property is a 0 to 1 multiplier for adding that roll rotation to the total. Only relevant ifDragStyleisDragDetectorDragStyle.RotateTrackball.WorldAxis
: Vector3NotReplicatedTheAxisexpressed in world space.The
Axisexpressed in world space. Relates to orientation using the same paradigm asAttachments.WorldSecondaryAxis
: Vector3NotReplicatedTheSecondaryAxisexpressed in world space.The
SecondaryAxisexpressed in world space. Relates to orientation using the same paradigm asAttachments.
Methods 5
AddConstraintFunction
(priority: int, function: Function) → RBXScriptConnectionAdds a function to modify or constrain proposed motion.Adds a function to modify or constrain proposed motion. The function takes an input
CFrameof proposed motion and returns aCFrameof modified or unmodified motion. Both the input and output are expressed relative to the reference frame. You can add multiple functions which will be called in order bypriority, passing the results along in a chain.To remove an added constraint function, call
Disconnect()on the returned connection object.GetReferenceFrame
() → CFrameReturns the referenceCFramein which motion is expressed.Returns the reference
CFramein which motion is expressed; see theReferenceInstanceproperty for more details.RestartDrag
() → ()May be invoked from a script to restart the drag using new parameters.May be invoked from a script to restart the drag using new parameters, if parameters such as
DragStyle,Axis, orSecondaryAxischange.SetDragStyleFunction
(function: Function) → ()Passes a function to be used if and only ifDragStyleis set toDragDetectorDragStyle.Scriptable.Passes a function to be used if and only if
DragStyleis set toDragDetectorDragStyle.Scriptable. The given function is called when responding to aDragContinuesignal, it receives the signal's world space cursor ray with typeRay, and it returns aCFramecontaining the desired location and orientation of the pivot in world space.If the function returns
nil, the object will not be moved. This is useful if the script has not yet collected all the information it needs to give the correct answer, or in temporary cases where you want the object to stay where it is.SetPermissionPolicyFunction
(function: Function) → ()Passes a function to be used if and only ifPermissionPolicyis set toDragDetectorPermissionPolicy.Scriptable.Passes a function to be used if and only if
PermissionPolicyis set toDragDetectorPermissionPolicy.Scriptable. The given function accepts aPlayerparameter for enabling/disabling the detector for a specific player. It also receives apartparameter indicating which specificBasePartwas clicked, such as one part within a draggableModel; this is useful for enabling/disabling the detector based on that part'sName,Color,HasTag()value, or other details.
Events 3
DragContinue
DragDetector.DragContinue:Connect(function(playerWhoDragged, cursorRay, viewFrame, vrInputFrame, isModeSwitchKeyDown))Fires when a user continues dragging the object afterDragStarthas been initiated.DragEnd
DragDetector.DragEnd:Connect(function(playerWhoDragged))Fires when a user stops dragging the object.DragStart
DragDetector.DragStart:Connect(function(playerWhoDragged, cursorRay, viewFrame, hitFrame, clickedPart, vrInputFrame, isModeSwitchKeyDown))Fires when a user starts dragging the object.
DragDetector also has every member of ClickDetector. Deprecated and Roblox-only members are hidden.
Reference text from the Roblox Creator Documentation, licensed CC BY 4.0, reorganized by rbxtoolshub.com · Studio 0.743.0.7431133.