DragDetectors [Beta]

Hi, I was wondering if there was a way to rotate objects while the mouse is stationary?

Right now, DragDetector:SetDragStyleFunction() is only called when you move the mouse, so my custom rotation variable won’t be put into affect until I move the mouse, which looks very bad and feels unresponsive.

Is there an way to fire the SetDragStyleFunction() after I change my rotation variable? I would’ve thought RestartDrag(), but that causes my object to start going crazy and jittering everywhere.

Rather than using the DragDetector to drag, you could just rotate it while the mouse is down.

[1] set the responseStyle to Custom so it doesn’t do anything when you drag
[2] just listen to dragStart and dragEnd, and run a stepped callback to update the rotation while the mouse us pressed.

Assuming you have your DragDetector below a part or model, and you set ResponseStyle to Custom, this script should do the trick:

local parent = script.Parent
local dd = parent.DragDetector
local steppedConnection = nil
-- change this to move faster or slower
local angularVelocity = 3
-- change this to rotate about a different axis
local rotateAxis = Vector3.new(1,0,0)

dd.DragStart:Connect(function()
	steppedConnection = game:GetService("RunService").Stepped:Connect(function(time, deltaTime)
		parent:PivotTo(parent:GetPivot() * CFrame.fromAxisAngle(rotateAxis, angularVelocity * deltaTime))
	end)
end)

dd.DragEnd:Connect(function()
	if steppedConnection then
		steppedConnection:Disconnect()
		steppedConnection = nil
	end
end)
1 Like

Hey if you want to play with some spongy mechanisms…
Here’s a little plugin I just published.

in the description is a link to a test world, and you should be able to edit that model in studio.

There’s a button to add springs between the parts in the selection, and another to add DragDetectors that let you pull things around in-game.
SpringifyDemo

1 Like

How can I use the Rotate Axis drag style while setting a rotate number like I can do in studio? (I don’t want it to move smoothly, I want it to snap to a specified value)

1 Like

Is there any plans to introduce TranslateLineorRotateAxis dragging style? I feel like it would be good in roleplay games where player can move parts and rotate it around.

1 Like

Hello @Fenriing ,

We do not have a plan to prebundle TranslateLineRotateAxis, but with a simple script you can have it… The DragStart and DragContinue callbacks receive the state of the modifier key. Then, based on whether it’s up or down, you can change the DragStyle. Make sure to call RestartDrag() after doing this to avoid jumps in location/rotation when you make this transition. This pattern works for any pair of styles you like.

local dragDetector = script.Parent.DragDetector

local function setDragStyle(isModeSwitchKeyDown)
--	print("isKeyDown = ", isModeSwitchKeyDown)
	local newDragStyle = if isModeSwitchKeyDown then Enum.DragDetectorDragStyle.RotateAxis else Enum.DragDetectorDragStyle.TranslateLine	
	if newDragStyle ~= dragDetector.DragStyle then
		dragDetector.DragStyle = newDragStyle
		dragDetector:RestartDrag()
	end
end

dragDetector.DragStart:Connect(function(playerWhoDragged: Player, cursorRay: Ray, viewFrame: CFrame, hitFrame: CFrame, clickedPart: BasePart, vrInputFrame, isModeSwitchKeyDown: boolean) 
	setDragStyle(isModeSwitchKeyDown)	
end)

dragDetector.DragContinue:Connect(function(player, cursorRay, viewFrame, vrInputFrame, isModeSwitchKeyDown: boolean)
	setDragStyle(isModeSwitchKeyDown)	
end)

The above script is built into the attached TranslateLineOrRotateAxis.rbxl example.
TranslateLineOrRotateAxis.rbxl (54.3 KB)

3 Likes

Thank you! This is exactly what I was looking for. :pray:

1 Like

How can I fix the drawers that it’s easier to pick stuff from it if it is to small it drag the drawers instead of the stuff I will make it so in the story of my game you need to find a key around the house and I makd different dragable things you need to open to find the key and pick it up and touch the door with it

ignore the mini map I tried to make things arcivable false if you touch something so it not clone to the mini map but that break the map in some way

@PrinceTybalt there still is an issue with the dragdettectors on mobile if I want to drag my puzzle it doesn’t directly drag and it are time based puzzles so it almost impossible to complete it in 1 min but I think I want it 30 sec buy the camera go before the dragdetectors able if I drag on the left