Reference API Roblox

Engine API

Website

Related

Reference API Roblox

DragDetector

Instance which facilitates and encourages interaction with 3D objects in an experience.

Member index 41

HistoryMember
645ActivatedCursorIcon: ContentId
576ApplyAtCenterOfMass: bool
576Axis: Vector3
576DragFrame: CFrame
576DragStyle: DragDetectorDragStyle
576Enabled: bool
576GamepadModeSwitchKeyCode: KeyCode
576KeyboardModeSwitchKeyCode: KeyCode
576MaxDragAngle: float
576MaxDragTranslation: Vector3
576MaxForce: float
576MaxTorque: float
576MinDragAngle: float
576MinDragTranslation: Vector3
576Orientation: Vector3
611PermissionPolicy: DragDetectorPermissionPolicy
576ReferenceInstance: Instance
576ResponseStyle: DragDetectorResponseStyle
576Responsiveness: float
576RunLocally: bool
576SecondaryAxis: Vector3
576TrackballRadialPullFactor: float
576TrackballRollFactor: float
576VRSwitchKeyCode: KeyCode
576WorldAxis: Vector3
576WorldSecondaryAxis: Vector3
583AddConstraintFunction(priority: int, function: Function): RBXScriptConnection
576GetReferenceFrame(): CFrame
576RestartDrag(): null
576SetDragStyleFunction(function: Function): null
611SetPermissionPolicyFunction(function: Function): null
576DragContinue(playerWhoDragged: Player, cursorRay: Ray, viewFrame: CFrame, vrInputFrame: OptionalCoordinateFrame, isModeSwitchKeyDown: bool)
576DragEnd(playerWhoDragged: Player)
576DragStart(playerWhoDragged: Player, cursorRay: Ray, viewFrame: CFrame, hitFrame: CFrame, clickedPart: BasePart, vrInputFrame: OptionalCoordinateFrame, isModeSwitchKeyDown: bool)
inherited from ClickDetector
645CursorIcon: ContentId
553MaxActivationDistance: float
483MouseClick(playerWhoClicked: Player)
483MouseHoverEnter(playerWhoHovered: Player)
483MouseHoverLeave(playerWhoHovered: Player)
483RightMouseClick(playerWhoClicked: Player)
553mouseClick(playerWhoClicked: Player)
inherited from Instance
553Archivable: bool
635Capabilities: SecurityCapabilities
553Name: string
553Parent: Instance
635Sandboxed: bool
616UniqueId: UniqueId
576AddTag(tag: string): null
573ClearAllChildren(): null
462Clone(): Instance
573Destroy(): null
486FindFirstAncestor(name: string): Instance
486FindFirstAncestorOfClass(className: string): Instance
486FindFirstAncestorWhichIsA(className: string): Instance
486FindFirstChild(name: string, recursive: bool = false): Instance
486FindFirstChildOfClass(className: string): Instance
486FindFirstChildWhichIsA(className: string, recursive: bool = false): Instance
486FindFirstDescendant(name: string): Instance
563GetActor(): Actor
486GetAttribute(attribute: string): Variant
462GetAttributeChangedSignal(attribute: string): RBXScriptSignal
631GetAttributes(): Dictionary
648GetChildren(): Instances
462GetDebugId(scopeLength: int = 4): string
486GetDescendants(): Array
486GetFullName(): string
641GetStyled(name: string): Variant
576GetTags(): Array
576HasTag(tag: string): bool
486IsAncestorOf(descendant: Instance): bool
486IsDescendantOf(ancestor: Instance): bool
580IsPropertyModified(name: string): bool
573Remove(): null
576RemoveTag(tag: string): null
580ResetPropertyToDefault(name: string): null
573SetAttribute(attribute: string, value: Variant): null
462WaitForChild(childName: string, timeOut: double): Instance
648children(): Instances
553clone(): Instance
573destroy(): null
553findFirstChild(name: string, recursive: bool = false): Instance
648getChildren(): Instances
553isDescendantOf(ancestor: Instance): bool
573remove(): null
462AncestryChanged(child: Instance, parent: Instance)
462AttributeChanged(attribute: string)
462ChildAdded(child: Instance)
462ChildRemoved(child: Instance)
462DescendantAdded(descendant: Instance)
462DescendantRemoving(descendant: Instance)
500Destroying()
553childAdded(child: Instance)
inherited from Object
647ClassName: string
647className: string
647GetPropertyChangedSignal(property: string): RBXScriptSignal
647IsA(className: string): bool
650isA(className: string): bool
647Changed(property: string)

Removed member index 1

HistoryMember
583RemoveConstraintFunction(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

Members 41

ActivatedCursorIcon

TypeDefault
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.

History 2

AddConstraintFunction

Parameters (2)
priorityint
functionFunction
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.

History 3

ApplyAtCenterOfMass

TypeDefault
boolfalse

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.

History 1

Axis

TypeDefault
Vector30, 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.

This property is not replicated. Its interface does not cross the network boundary.

History 1

Tags: [NotReplicated]

DragContinue

Parameters (5)
playerWhoDraggedPlayer
cursorRayRay
viewFrameCFrame
vrInputFrameOptionalCoordinateFrame
isModeSwitchKeyDownbool

Fires when a user continues dragging the object after DragStart has been initiated.

History 1

DragEnd

Parameters (1)
playerWhoDraggedPlayer

Fires when a user stops dragging the object.

History 1

DragFrame

TypeDefault
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.

History 1

DragStart

Parameters (7)
playerWhoDraggedPlayer
cursorRayRay
viewFrameCFrame
hitFrameCFrame
clickedPartBasePart
vrInputFrameOptionalCoordinateFrame
isModeSwitchKeyDownbool

Fires when a user starts dragging the object.

History 1

DragStyle

TypeDefault
DragDetectorDragStyleTranslatePlane

The paradigm used to generate proposed motion, given a stream of cursor rays. See DragDetectorDragStyle for options.

History 1

Enabled

TypeDefault
booltrue

If true, the DragDetector responds to user input; if false, it does not.

History 1

GamepadModeSwitchKeyCode

TypeDefault
KeyCodeButtonR1

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.

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.

History 1

KeyboardModeSwitchKeyCode

TypeDefault
KeyCodeLeftControl

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.

History 1

MaxDragAngle

TypeDefault
float0

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.

History 1

MaxDragTranslation

TypeDefault
Vector30, 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.

History 1

MaxForce

TypeDefault
float10000000

Maximum force applied for the object to reach its goal. Only relevant if ResponseStyle is DragDetectorResponseStyle.Physical and the parent object is unanchored.

History 1

MaxTorque

TypeDefault
float10000

Maximum torque applied for the object to reach its goal. Only relevant if ResponseStyle is DragDetectorResponseStyle.Physical and the parent object is unanchored.

History 1

MinDragAngle

TypeDefault
float0

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.

History 1

MinDragTranslation

TypeDefault
Vector30, 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.

History 1

Orientation

TypeDefault
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.

History 1

PermissionPolicy

TypeDefault
DragDetectorPermissionPolicyEverybody

Controls the permission level for which players can interact with the DragDetector. Default is DragDetectorPermissionPolicy.Everybody.

History 1

ReferenceInstance

TypeDefault
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.

History 1

ResponseStyle

TypeDefault
DragDetectorResponseStylePhysical

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.

History 1

Responsiveness

TypeDefault
float10

Higher values cause the object to reach its goal more rapidly. Only relevant if ResponseStyle is DragDetectorResponseStyle.Physical and the parent object is unanchored.

History 1

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.

History 1

RunLocally

TypeDefault
boolfalse

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.

History 1

SecondaryAxis

TypeDefault
Vector31, 0, 0

The secondary axis of the motion. Relates to orientation using the same paradigm as Attachments.

This property is not replicated. Its interface does not cross the network boundary.

History 1

Tags: [NotReplicated]

SetDragStyleFunction

Parameters (1)
functionFunction
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.

History 1

SetPermissionPolicyFunction

Parameters (1)
functionFunction
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
local dragDetector = script.Parent.DragDetector
dragDetector.PermissionPolicy = Enum.DragDetectorPermissionPolicy.Scriptable

dragDetector:SetPermissionPolicyFunction(function(player, part)
	if player and player:GetAttribute("IsInTurn") then
		return true
	elseif part and not part:GetAttribute("IsDraggable") then
		return false
	else
		return true
	end
end)

History 1

TrackballRadialPullFactor

TypeDefault
float1

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.

History 1

TrackballRollFactor

TypeDefault
float1

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.

History 1

VRSwitchKeyCode

TypeDefault
KeyCodeButtonL2

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.

History 1

WorldAxis

TypeDefault
Vector30, 1, 0

The Axis expressed in world space. Relates to orientation using the same paradigm as Attachments.

This property is not replicated. Its interface does not cross the network boundary.

History 1

Tags: [NotReplicated]

WorldSecondaryAxis

TypeDefault
Vector31, 0, 0

The SecondaryAxis expressed in world space. Relates to orientation using the same paradigm as Attachments.

This property is not replicated. Its interface does not cross the network boundary.

History 1

Tags: [NotReplicated]

Removed members 1

RemoveConstraintFunction

Parameters (1)
namestring
Returns (1)
null

History 2

Settings