DragDetector
Instance which facilitates and encourages interaction with 3D objects in an experience.
Memory category | Instances |
---|
Member index 41
Removed member index 1
History | Member | |
---|---|---|
583 | RemoveConstraintFunction(name: string): null |
Description
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 DragDetector under any BasePart or Model to make it draggable via all inputs (mouse, touch, gamepad, and VR), all without a single line of code.
Choose from several DragStyle options, define how the object responds to motion via ResponseStyle, 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.
DragDetectors work 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.
History 48
- 645 Change ValueType of ActivatedCursorIcon from Content to ContentId
- 616 Add
- 616 Add
- 616 Add
- 611 Add SetPermissionPolicyFunction
- 611 Add PermissionPolicy
- 598 Change Tags of DragDetector from [NotBrowsable] to []
- 589 Add
- 583 Remove RemoveConstraintFunction
- 583 Change ReturnType of AddConstraintFunction from null to RBXScriptConnection
- 583 Change Parameters of AddConstraintFunction from (name: string, priority: int, function: Function) to (priority: int, function: Function)
- 580 Add ActivatedCursorIcon
- 576 Add DragStart
- 576 Add DragEnd
- 576 Add DragContinue
- 576 Add SetDragStyleFunction
- 576 Add RestartDrag
- 576 Add RemoveConstraintFunction
- 576 Add GetReferenceFrame
- 576 Add AddConstraintFunction
- 576 Add WorldSecondaryAxis
- 576 Add WorldAxis
- 576 Add VRSwitchKeyCode
- 576 Add TrackballRollFactor
- 576 Add TrackballRadialPullFactor
- 576 Add SecondaryAxis
- 576 Add RunLocally
- 576 Add Responsiveness
- 576 Add ResponseStyle
- 576 Add ReferenceInstance
- 576 Add
- 576 Add
- 576 Add
- 576 Add Orientation
- 576 Add MinDragTranslation
- 576 Add MinDragAngle
- 576 Add MaxTorque
- 576 Add MaxForce
- 576 Add MaxDragTranslation
- 576 Add MaxDragAngle
- 576 Add KeyboardModeSwitchKeyCode
- 576 Add GamepadModeSwitchKeyCode
- 576 Add Enabled
- 576 Add DragStyle
- 576 Add DragFrame
- 576 Add Axis
- 576 Add ApplyAtCenterOfMass
- 576 Add DragDetector
Members 41
ActivatedCursorIcon
Type | Default | |
---|---|---|
ContentId |
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.
Thread safety | ReadSafe |
---|---|
Category | Image |
Loaded/Saved | true |
History 2
- 645 Change ValueType of ActivatedCursorIcon from Content to ContentId
- 580 Add ActivatedCursorIcon
AddConstraintFunction
Parameters (2) | ||
---|---|---|
priority | int | |
function | Function | |
Returns (1) | ||
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.
Thread safety | Unsafe |
---|
History 3
- 583 Change ReturnType of AddConstraintFunction from null to RBXScriptConnection
- 583 Change Parameters of AddConstraintFunction from (name: string, priority: int, function: Function) to (priority: int, function: Function)
- 576 Add AddConstraintFunction
ApplyAtCenterOfMass
Type | Default | |
---|---|---|
bool | false |
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.
Thread safety | ReadSafe |
---|---|
Category | Physics Response |
Loaded/Saved | true |
History 1
Axis
Type | Default | |
---|---|---|
Vector3 | 0, 1, 0 |
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.
Thread safety | ReadSafe |
---|---|
Category | Drag Directions |
Loaded/Saved | true/false |
DragContinue
Parameters (5) | |
---|---|
playerWhoDragged | Player |
cursorRay | Ray |
viewFrame | CFrame |
vrInputFrame | OptionalCoordinateFrame |
isModeSwitchKeyDown | bool |
Fires when a user continues dragging the object after DragStart has been initiated.
Thread safety | Unsafe |
---|
History 1
- 576 Add DragContinue
DragEnd
Parameters (1) | |
---|---|
playerWhoDragged | Player |
Fires when a user stops dragging the object.
Thread safety | Unsafe |
---|
DragFrame
Type | Default | |
---|---|---|
CFrame |
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.
Thread safety | ReadSafe |
---|---|
Category | Dragged Amount |
Loaded/Saved | true |
DragStart
Parameters (7) | |
---|---|
playerWhoDragged | Player |
cursorRay | Ray |
viewFrame | CFrame |
hitFrame | CFrame |
clickedPart | BasePart |
vrInputFrame | OptionalCoordinateFrame |
isModeSwitchKeyDown | bool |
Fires when a user starts dragging the object.
Thread safety | Unsafe |
---|
DragStyle
Type | Default | |
---|---|---|
DragDetectorDragStyle | TranslatePlane |
The paradigm used to generate proposed motion, given a stream of cursor rays. See DragDetectorDragStyle for options.
Thread safety | ReadSafe |
---|---|
Category | Behavior |
Loaded/Saved | true |
Enabled
Type | Default | |
---|---|---|
bool | true |
If true, the DragDetector responds to user input; if false, it does not.
Thread safety | ReadSafe |
---|---|
Category | Behavior |
Loaded/Saved | true |
GamepadModeSwitchKeyCode
Type | Default | |
---|---|---|
KeyCode | ButtonR1 |
During gamepad input, the KeyCode for toggling the secondary mode of motion. Only applies if the drag detector's DragStyle has both primary and secondary modes of motion.
Thread safety | ReadSafe |
---|---|
Category | Mode Switching |
Loaded/Saved | true |
History 1
GetReferenceFrame
Parameters (0) | ||
---|---|---|
No parameters. | ||
Returns (1) | ||
CFrame |
Returns the reference CFrame in which motion is expressed; see the ReferenceInstance property for more details.
Thread safety | Unsafe |
---|
History 1
- 576 Add GetReferenceFrame
KeyboardModeSwitchKeyCode
Type | Default | |
---|---|---|
KeyCode | LeftControl |
During keyboard input, the KeyCode for toggling the secondary mode of motion. Only applies if the drag detector's DragStyle has both primary and secondary modes of motion.
Thread safety | ReadSafe |
---|---|
Category | Mode Switching |
Loaded/Saved | true |
History 1
MaxDragAngle
Type | Default | |
---|---|---|
float | 0 |
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.
Thread safety | ReadSafe |
---|---|
Category | Drag Limits |
Loaded/Saved | true |
History 1
- 576 Add MaxDragAngle
MaxDragTranslation
Type | Default | |
---|---|---|
Vector3 | 0, 0, 0 |
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.
Thread safety | ReadSafe |
---|---|
Category | Drag Limits |
Loaded/Saved | true |
History 1
MaxForce
Type | Default | |
---|---|---|
float | 10000000 |
Maximum force applied for the object to reach its goal. Only relevant if ResponseStyle is DragDetectorResponseStyle.Physical and the parent object is unanchored.
Thread safety | ReadSafe |
---|---|
Category | Physics Response |
Loaded/Saved | true |
MaxTorque
Type | Default | |
---|---|---|
float | 10000 |
Maximum torque applied for the object to reach its goal. Only relevant if ResponseStyle is DragDetectorResponseStyle.Physical and the parent object is unanchored.
Thread safety | ReadSafe |
---|---|
Category | Physics Response |
Loaded/Saved | true |
MinDragAngle
Type | Default | |
---|---|---|
float | 0 |
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.
Thread safety | ReadSafe |
---|---|
Category | Drag Limits |
Loaded/Saved | true |
History 1
- 576 Add MinDragAngle
MinDragTranslation
Type | Default | |
---|---|---|
Vector3 | 0, 0, 0 |
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.
Thread safety | ReadSafe |
---|---|
Category | Drag Limits |
Loaded/Saved | true |
History 1
Orientation
Type | Default | |
---|---|---|
Vector3 | -0, 180, 90 |
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.
Thread safety | ReadSafe |
---|---|
Category | Drag Directions |
Loaded/Saved | true |
History 1
- 576 Add Orientation
PermissionPolicy
Type | Default | |
---|---|---|
DragDetectorPermissionPolicy | Everybody |
Controls the permission level for which players can interact with the DragDetector. Default is DragDetectorPermissionPolicy.Everybody.
Thread safety | ReadSafe |
---|---|
Category | Behavior |
Loaded/Saved | true |
History 1
- 611 Add PermissionPolicy
ReferenceInstance
Type | Default | |
---|---|---|
Instance |
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.
Thread safety | ReadSafe |
---|---|
Category | Data |
Loaded/Saved | true |
History 1
- 576 Add ReferenceInstance
ResponseStyle
Type | Default | |
---|---|---|
DragDetectorResponseStyle | Physical |
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.
Thread safety | ReadSafe |
---|---|
Category | Behavior |
Loaded/Saved | true |
History 1
- 576 Add ResponseStyle
Responsiveness
Type | Default | |
---|---|---|
float | 10 |
Higher values cause the object to reach its goal more rapidly. Only relevant if ResponseStyle is DragDetectorResponseStyle.Physical and the parent object is unanchored.
Thread safety | ReadSafe |
---|---|
Category | Physics Response |
Loaded/Saved | true |
History 1
- 576 Add Responsiveness
RestartDrag
Parameters (0) | ||
---|---|---|
No parameters. | ||
Returns (1) | ||
null |
May be invoked from a script to restart the drag using new parameters, if parameters such as DragStyle, Axis, or SecondaryAxis change.
Thread safety | Unsafe |
---|
History 1
- 576 Add RestartDrag
RunLocally
Type | Default | |
---|---|---|
bool | false |
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.
Thread safety | ReadSafe |
---|---|
Category | Behavior |
Loaded/Saved | true |
History 1
- 576 Add RunLocally
SecondaryAxis
Type | Default | |
---|---|---|
Vector3 | 1, 0, 0 |
The secondary axis of the motion. Relates to orientation using the same paradigm as Attachments.
Thread safety | ReadSafe |
---|---|
Category | Drag Directions |
Loaded/Saved | true/false |
History 1
- 576 Add SecondaryAxis
SetDragStyleFunction
Parameters (1) | ||
---|---|---|
function | Function | |
Returns (1) | ||
null |
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.
Thread safety | Unsafe |
---|
History 1
SetPermissionPolicyFunction
Parameters (1) | ||
---|---|---|
function | Function | |
Returns (1) | ||
null |
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.
1 2 3 4 5 6 7 8 9 10 11 12 |
|
Thread safety | Unsafe |
---|
History 1
TrackballRadialPullFactor
Type | Default | |
---|---|---|
float | 1 |
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.
Thread safety | ReadSafe |
---|---|
Category | Behavior |
Loaded/Saved | true |
History 1
TrackballRollFactor
Type | Default | |
---|---|---|
float | 1 |
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.
Thread safety | ReadSafe |
---|---|
Category | Behavior |
Loaded/Saved | true |
History 1
VRSwitchKeyCode
Type | Default | |
---|---|---|
KeyCode | ButtonL2 |
During VR input, the KeyCode for toggling the secondary mode of motion. Only applies if the drag detector's DragStyle has both primary and secondary modes of motion.
Thread safety | ReadSafe |
---|---|
Category | Mode Switching |
Loaded/Saved | true |
History 1
- 576 Add VRSwitchKeyCode
WorldAxis
Type | Default | |
---|---|---|
Vector3 | 0, 1, 0 |
The Axis expressed in world space. Relates to orientation using the same paradigm as Attachments.
Thread safety | ReadSafe |
---|---|
Category | Drag Directions |
Loaded/Saved | true/false |
WorldSecondaryAxis
Type | Default | |
---|---|---|
Vector3 | 1, 0, 0 |
The SecondaryAxis expressed in world space. Relates to orientation using the same paradigm as Attachments.
Thread safety | ReadSafe |
---|---|
Category | Drag Directions |
Loaded/Saved | true/false |