Class
DragDetector
Instance which facilitates and encourages interaction with 3D objects in an experience.
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#
ActivatedCursorIconContentId | Sets the cursor icon to display when the mouse is activated over the
parent of this DragDetector.ReadSafe |
ActivatedCursorIconContentContent | Sets the cursor icon to display when the mouse is activated over the
parent of this DragDetector. Only supports asset URIsReadSafe |
ApplyAtCenterOfMassboolean | Whether constraint force is applied to the object's center of mass.ReadSafe |
AxisVector3 | The primary axis of motion, expressed relative to the reference frame.ReadSafeNotReplicated |
DragFrameCFrame | The CFrame of the pivot, dependent on the drag detector's
ReferenceInstance.ReadSafe |
DragStyleDragDetectorDragStyle | The paradigm used to generate proposed motion.ReadSafe |
Enabledboolean | Whether the DragDetector responds to user input.ReadSafe |
GamepadModeSwitchKeyCodeKeyCode | During gamepad input, the modifier KeyCode for the secondary mode
of motion.ReadSafe |
KeyboardModeSwitchKeyCodeKeyCode | During keyboard input, the modifier KeyCode for the secondary mode
of motion.ReadSafe |
MaxDragAnglefloat | Along with MinDragAngle, impedes the
drag detector's attempts to generate motion.ReadSafe |
MaxDragTranslationVector3 | Along with MinDragTranslation,
impedes the drag detector's attempts to generate motion.ReadSafe |
MaxForcefloat | Maximum force applied for the object to reach its goal.ReadSafe |
MaxTorquefloat | Maximum torque applied for the object to reach its goal.ReadSafe |
MinDragAnglefloat | Along with MaxDragAngle, impedes the
drag detector's attempts to generate motion.ReadSafe |
MinDragTranslationVector3 | Along with MaxDragTranslation,
impedes the drag detector's attempts to generate motion.ReadSafe |
OrientationVector3 | Specifies the YXZ rotation of axes of motion relative to the reference frame.ReadSafe |
PermissionPolicyDragDetectorPermissionPolicy | Controls the permission level for which players can interact with the
DragDetector.ReadSafe |
ReferenceInstanceInstance | An instance whose CFrame is the reference frame for the drag
detector.ReadSafe |
ResponseStyleDragDetectorResponseStyle | The paradigm used to move, or not move, the objects affected by the drag detector.ReadSafe |
Responsivenessfloat | Higher values cause the object to reach its goal more rapidly.ReadSafe |
RunLocallyboolean | Whether user input on a DragDetector replicates to the server or
remains local to the specific client.ReadSafe |
SecondaryAxisVector3 | The secondary axis of the motion.ReadSafeNotReplicated |
TrackballRadialPullFactorfloat | If DragStyle is
DragDetectorDragStyle.RotateTrackball, multiplier for adding a
radial pull rotation as a contribution to the total.ReadSafe |
TrackballRollFactorfloat | If DragStyle is
DragDetectorDragStyle.RotateTrackball, multiplier for adding roll
rotation to the total.ReadSafe |
VRSwitchKeyCodeKeyCode | During VR input, the modifier KeyCode for the secondary mode of
motion.ReadSafe |
WorldAxisVector3 | The Axis expressed in world space.ReadSafeNotReplicated |
WorldSecondaryAxisVector3 | The SecondaryAxis expressed in world
space.ReadSafeNotReplicated |
ActivatedCursorIcon: ContentId#
ReadSafe
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: Content#
ReadSafe
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. Only asset URIs are supported for this property.
ApplyAtCenterOfMass: boolean#
ReadSafe
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 ResponseStyle is
DragDetectorResponseStyle.Physical and the parent object is
unanchored.
Axis: Vector3#
NotReplicatedReadSafe
The primary axis of motion, expressed relative to the reference frame. For
a DragStyle of
DragDetectorDragStyle.TranslateLine, the direction of translation;
for DragDetectorDragStyle.TranslatePlane, the normal to the plane
of motion; for DragDetectorDragStyle.RotateAxis, the axis of 1D
rotation. Changing this value automatically updates
Orientation and vice versa.
DragFrame: CFrame#
ReadSafe
If ReferenceInstance is set, the
CFrame of the pivot relative to the reference frame; otherwise,
the CFrame of the pivot relative to its frame at the beginning
of the drag.
DragStyle: DragDetectorDragStyle#
ReadSafe
The paradigm used to generate proposed motion, given a stream of cursor
rays. See DragDetectorDragStyle for options.
Enabled: boolean#
ReadSafe
If true, the DragDetector responds to user input; if false, it
does not.
GamepadModeSwitchKeyCode: KeyCode#
ReadSafe
KeyboardModeSwitchKeyCode: KeyCode#
ReadSafe
MaxDragAngle: float#
ReadSafe
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 DragStyle is
DragDetectorDragStyle.RotateAxis.
MaxDragTranslation: Vector3#
ReadSafe
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: float#
ReadSafe
Maximum force applied for the object to reach its goal. Only relevant if
ResponseStyle is
DragDetectorResponseStyle.Physical and the parent object is
unanchored.
MaxTorque: float#
ReadSafe
Maximum torque applied for the object to reach its goal. Only relevant if
ResponseStyle is
DragDetectorResponseStyle.Physical and the parent object is
unanchored.
MinDragAngle: float#
ReadSafe
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 DragStyle is
DragDetectorDragStyle.RotateAxis.
MinDragTranslation: Vector3#
ReadSafe
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: Vector3#
ReadSafe
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 Axis and vice versa.
PermissionPolicy: DragDetectorPermissionPolicy#
ReadSafe
Controls the permission level for which players can interact with the
DragDetector. Default is
DragDetectorPermissionPolicy.Everybody.
ReferenceInstance: Instance#
ReadSafe
An instance whose CFrame is the reference frame for the drag
detector. The DragFrame is expressed
relative to this CFrame which may be retrieved via the
GetReferenceFrame() method.
If this instance is a PVInstance, the reference frame will be its
pivot; if an Attachment, then its world CFrame. If it
is nil or neither of the former, the reference frame will be based on
the pivot of the drag detector's parent BasePart or Model.
ResponseStyle: DragDetectorResponseStyle#
ReadSafe
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. See DragDetectorResponseStyle for
options.
Responsiveness: float#
ReadSafe
Higher values cause the object to reach its goal more rapidly. Only
relevant if ResponseStyle is
DragDetectorResponseStyle.Physical and the parent object is
unanchored.
RunLocally: boolean#
ReadSafe
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 LocalScripts may be used to
respond to these events and RemoteEvents may be used
to send any resulting changes that should be replicated to the server.
SecondaryAxis: Vector3#
NotReplicatedReadSafe
The secondary axis of the motion. Relates to orientation using the same
paradigm as Attachments.
TrackballRadialPullFactor: float#
ReadSafe
When the cursor is outside the trackball, the DragDetector can
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 if
DragStyle is
DragDetectorDragStyle.RotateTrackball.
TrackballRollFactor: float#
ReadSafe
When the cursor is outside the trackball, the DragDetector can
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 if
DragStyle is
DragDetectorDragStyle.RotateTrackball.
VRSwitchKeyCode: KeyCode#
ReadSafe
WorldAxis: Vector3#
NotReplicatedReadSafe
The Axis expressed in world space. Relates to
orientation using the same paradigm as Attachments.
WorldSecondaryAxis: Vector3#
NotReplicatedReadSafe
The SecondaryAxis expressed in world
space. Relates to orientation using the same paradigm as
Attachments.
Methods 5#
| AddConstraintFunction | Adds a function to modify or constrain proposed motion. |
| GetReferenceFrame | Returns the reference CFrame in which motion is expressed. |
| RestartDrag | May be invoked from a script to restart the drag using new parameters. |
| SetDragStyleFunction | Passes a function to be used if and only if
DragStyle is set to
DragDetectorDragStyle.Scriptable. |
| SetPermissionPolicyFunction | Passes a function to be used if and only if
PermissionPolicy is set to
DragDetectorPermissionPolicy.Scriptable. |
AddConstraintFunction(priority: int, function: Function): RBXScriptConnection#
Adds a function to modify or constrain proposed motion. The function takes
an input CFrame of proposed motion and returns a
CFrame of 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 by priority, passing the results
along in a chain.
To remove an added constraint function, call
Disconnect() on the returned
connection object.
| Name | Type | Default | Description |
|---|---|---|---|
priority | int | The order of priority for functions added via this method. Higher values take precedence over lower values. | |
function | Function | Function for modifying or constraining proposed motion. This function
takes an input CFrame of proposed motion and returns a
CFrame of modified or unmodified motion, both relative
to the reference frame. |
Returns
RBXScriptConnection— Use this connection object to remove the constraint function.
GetReferenceFrame(): CFrame#
Returns the reference CFrame in which motion is expressed; see
the ReferenceInstance property for
more details.
RestartDrag(): ()#
May be invoked from a script to restart the drag using new parameters, if
parameters such as DragStyle,
Axis, or
SecondaryAxis change.
Returns
()
SetDragStyleFunction(function: Function): ()#
Passes a function to be used if and only if
DragStyle is set to
DragDetectorDragStyle.Scriptable. The given function is called when
responding to a DragContinue signal, it
receives the signal's world space cursor ray with type Ray, and
it returns a CFrame containing 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.
| Name | Type | Default | Description |
|---|---|---|---|
function | Function | Function for monitoring DragContinue
signals. This function receives the signal's world space cursor ray
and it returns a CFrame containing the desired location and
orientation of the pivot in world space. If this function returns
nil, the object will not be moved. |
Returns
()
SetPermissionPolicyFunction(function: Function): ()#
Passes a function to be used if and only if
PermissionPolicy is set to
DragDetectorPermissionPolicy.Scriptable. The given function accepts
a Player parameter for enabling/disabling the detector for a
specific player. It also receives a part parameter indicating which
specific BasePart was clicked, such as one part within a draggable
Model; this is useful for enabling/disabling the detector based on
that part's Name, Color,
HasTag() value, or other details.
| Name | Type | Default | Description |
|---|---|---|---|
function | Function | Function for setting the detector's interactivity. This function
accepts a Player parameter for enabling/disabling the detector
for a specific player. It also receives a part parameter indicating
which specific BasePart was clicked, such as one part within a
draggable Model; this is useful for enabling/disabling the
detector based on that part's Name,
Color, HasTag()
value, or other details. |
Returns
()
Events 3#
| DragContinue | Fires when a user continues dragging the object after
DragStart has been initiated. |
| DragEnd | Fires when a user stops dragging the object. |
| DragStart | Fires when a user starts dragging the object. |
DragContinue(playerWhoDragged: Player, cursorRay: Ray, viewFrame: CFrame, vrInputFrame: OptionalCoordinateFrame, isModeSwitchKeyDown: boolean)#
Fires when a user continues dragging the object after
DragStart has been initiated.
| Name | Type | Default | Description |
|---|---|---|---|
playerWhoDragged | Player | The Player who initiated the drag through
DragStart and is now continuing the
drag. | |
cursorRay | Ray | Ray emanating from the cursor, aimed into the scene. | |
viewFrame | CFrame | CFrame of the user's Camera. | |
vrInputFrame | OptionalCoordinateFrame | If using a VR input device, the CFrame of the hand holding
the cursor/pointer/controller. | |
isModeSwitchKeyDown | boolean | If the drag detector's DragStyle has
both primary and secondary modes of motion, this parameter indicates
whether the user is pressing the modifier input defined through
KeyboardModeSwitchKeyCode,
GamepadModeSwitchKeyCode,
or VRSwitchKeyCode. |
DragEnd(playerWhoDragged: Player)#
Fires when a user stops dragging the object.
DragStart(playerWhoDragged: Player, cursorRay: Ray, viewFrame: CFrame, hitFrame: CFrame, clickedPart: BasePart, vrInputFrame: OptionalCoordinateFrame, isModeSwitchKeyDown: boolean)#
Fires when a user starts dragging the object.
| Name | Type | Default | Description |
|---|---|---|---|
playerWhoDragged | Player | Player who initiated the drag. | |
cursorRay | Ray | Ray emanating from the cursor, aimed into the scene. | |
viewFrame | CFrame | CFrame of the user's Camera. | |
hitFrame | CFrame | The hit frame of the cursor raycast that initiated the drag. | |
clickedPart | BasePart | The part that was hit by the cursor raycast that initiated the drag. | |
vrInputFrame | OptionalCoordinateFrame | If using a VR input device, the CFrame of the hand holding
the cursor/pointer/controller. | |
isModeSwitchKeyDown | boolean | If the drag detector's DragStyle has
both primary and secondary modes of motion, this parameter indicates
whether the user is pressing the modifier input defined through
KeyboardModeSwitchKeyCode,
GamepadModeSwitchKeyCode,
or VRSwitchKeyCode. |
Inherited members#
Inherited from ClickDetector 8
Properties (3)
Events (5)
MouseClick, mouseClick, MouseHoverEnter, MouseHoverLeave, RightMouseClick
Inherited from Instance 58
Properties (10)
Archivable, archivable, Capabilities, IsInSandbox, Name, Parent, PredictionMode, RobloxLocked, Sandboxed, UniqueId
Methods (39)
AddTag, children, ClearAllChildren, Clone, clone, Destroy, destroy, FindFirstAncestor, FindFirstAncestorOfClass, FindFirstAncestorWhichIsA, FindFirstChild, findFirstChild, FindFirstChildOfClass, FindFirstChildWhichIsA, FindFirstDescendant, GetActor, GetAttribute, GetAttributeChangedSignal, GetAttributes, GetChildren, getChildren, GetDebugId, GetDescendants, GetFullName, GetStyled, GetStyledPropertyChangedSignal, GetTags, HasTag, IsAncestorOf, IsDescendantOf, isDescendantOf, IsPropertyModified, QueryDescendants, Remove, remove, RemoveTag, ResetPropertyToDefault, SetAttribute, WaitForChild