DragDetectors [Beta]

I gave SetDragStyleFunction a whirl tonight and ran into a few issues. Let me explain what I was trying to use it for first. I tried to use it to position a draggable object in front of the character at all times. The script positioned the object in front of the character’s head if the player was in third person. If the player was in first person, the object would be positioned wherever their mouse is on the viewport. In most circumstances, that’d be in the center of the screen. Here’s what the script looked like:

local DISTANCE_FROM_CHARACTER = 4

local dragDetector = script.Parent
local draggablePart = dragDetector.Parent

local currentCamera = workspace.CurrentCamera
local currentGuiInset = game:GetService("GuiService"):GetGuiInset()

local function shouldUseHeadAsOrigin(): (boolean, CFrame?)
	local cameraSubject = currentCamera.CameraSubject
	if cameraSubject then
		local isLockedToHead = cameraSubject:IsA("Humanoid")
		if not isLockedToHead then
			return false
		end
		
		local currentHead = cameraSubject.Parent:FindFirstChild("Head")
		if currentHead==nil then
			return false
		end
		
		local currentCameraFocusPosition = currentCamera.Focus.Position
		local currentCameraPosition = currentCamera.CFrame.Position
		local isCameraInFirstPerson = (currentCameraFocusPosition-currentCameraPosition).Magnitude < 0.75
		
		if not isCameraInFirstPerson then			
			return true, currentHead.CFrame
		end
	end
	return false
end

dragDetector:SetDragStyleFunction(function()
	local shouldUseHead, headCFrame = shouldUseHeadAsOrigin()
	if shouldUseHead then
		return CFrame.new(headCFrame.Position + headCFrame.LookVector * DISTANCE_FROM_CHARACTER) * headCFrame.Rotation
	end
	
	local currentMouseLocation = game:GetService("UserInputService"):GetMouseLocation() - currentGuiInset
	local viewportCursorRay = currentCamera:ViewportPointToRay(currentMouseLocation.X, currentMouseLocation.Y)

	return CFrame.new(viewportCursorRay.Origin + viewportCursorRay.Direction * DISTANCE_FROM_CHARACTER) * currentCamera.CFrame.Rotation
end)

All the DragDetectors in this post use RunLocally.

Mysterious DragStyleFunction Parameter

The first issue I ran into was that I had no clue what parameters were passed to the DragStyleFunction from the docs and from studio’s intellisense. The only hint that it passed down a parameter was this part from the documentation:

it receives the signal’s world space cursor ray

Which in itself is a bit vague. It mentions the cursor, but from what I saw, it’s not the same as what I did with my DragStyleFunction for the viewportCursorRay variable. It’d be nice if there was a small explanation of what the parameter really is. In addition, a simple example function that could be passed to SetDragStyleFunction on the doc site that shows off that parameter would be handy as well.

Missing AlignOrientation for Scriptable DragStyle

I was messing around with the draggable object that used the code above and I noticed that the orientation of the object didn’t match what I was giving through my DragStyleFunction. I was heavily confused because the docs said this about the CFrame that the function returns:

it returns a CFrame containing the desired location and orientation of the pivot in world space

After a bit of investigating, apparently no AlignOrientation object is created when using a Scriptable DragStyle plus the Physical ResponseStyle. The Geometric ResponseStyle works as expected, so this definitely looks to be unintentional. Here’s what it looks like:

As you can see, the part with the Geometric ResponseStyle always has the red face pointing towards the character, like it’s supposed to. However, with the one that has the ResponseStyle set to Physical, it doesn’t do anything with the orientation.

Stuttering with Geometric Dragging in First Person

When dragging an object with the ResponseStyle set to Geometric, the object stutters since it’s being CFramed after the frame has been rendered, leading the object to being always a frame behind position wise. With this ReponseStyle, I don’t think this should be happening. Here’s a quick look at that:

Unexpected Positioning

When using the Geometric ResponseStyle, the object is positioned at the CFrame I returned with my DragStyleFunction (as seen in the video above), like I expected. However, when using the Physical ResponseStyle, the object rarely seems to be positioned correctly, if ever. I’m not sure what exactly is going on here. Here’s what that looks like:

In that video, I would expect the starting drag point to be where the cursor is. At the end though, you can see the cursor be on the opposite side of the part where the drag originated. No clue if that makes sense. The DragStyle being used here is the same as earlier (scriptable with the snippet at the top).

The DragDetector does indeed have ApplyAtCenterOfMass enabled in that video. However, with or without it enabled, I still get unexpected results with where the object is ending up.

Constraints Remaining after Dying

If a player is dragging a DragDetector when their character respawns, the AlignPosition and AlignOrientation constraints aren’t cleaned up until a different player tries dragging the object. There’s also some kind of desync when the ResponseStyle is Geometric (the client has it frozen but the server doesn’t).

This means if a player dies while falling and dragging an object, the object has the potential to be stuck floating in the air and out of reach.

6 Likes

Hmm. I must admit I am not super acquainted with all the details about saving and publishing. But I don’t think that collaborative editing automatically publishes your creation, it just saves it for Team Create in Studio. I did some testing and it seemed that way for all changes to the game. Are you seeing different behavior for changing the axis than for say duplicating a block?
If you click “publish to Roblox” I would bet that your changes make it to the published game.

What is the error you get when you try to set the axis with a script?
(You shouldn’t have to do this. You should just need to re-publish. But I’m curious what error you are seeing).

Attachments and constraints are very tricky to get right, unfortunately. Without seeing your example it’s hard to guide you how to use them. But also you probably don’t need them, you probably just need to set “ApplyAtCenterOfMass” to true like I mentioned in the prior message.

3 Likes

Thank you @YasuYoshida this is amazing and detailed feedback.
I will take some time to go through all this (hopefully today) and post a complete response.

5 Likes

See my reply to the original announcement, just below this one. We are not leaving the beta period yet, but you can sign up to have us turn on DragDetectors in your published game.

3 Likes

@WooleyWool @IAmPinleon @nlsnjr you may be interested in signing up for the DragDetector “beta for Places” below.

4 Likes

@here
@here Greetings!

Some of you are eager to try out and share DragDetectors in your games.
Even though we are still in beta, we can enable DragDetectors for specific published games.

So we are going to let you try it out.There is a link to a form below, but before you sign up, please be aware:
THINGS ARE GOING TO CHANGE. YOUR GAME MAY BREAK IF YOU DON’T UPDATE FOR CHANGED API. AND ASPECTS OF BEHAVIOR MAY CHANGE/IMPROVE.

Also: WE WILL NOT ENABLE YOUR GAME UNLESS YOU USE YOUR USERNAME IN THE FORM, NOT A GROUP NAME, AND THAT USER ALSO LIKES THIS REPLY
This is because some sneaky folks tried to get us to turn it on in other peoples’ games. Tsk, Tsk, Tsk. So we are going to check that the requestor is a valid owner or developer of the game.

Here is a list of issues you’ll need to consider. It will also help you understand what we hope to accomplish before we change from beta to a full feature release:

  • Add and Remove Constraint API signature will change and may break my code
  • In Geometric Mode, all nonanchored parts in a model will be anchored when moving, not just the clicked part
  • Behavior of constraints that control non-anchored objects may change slightly
  • Simulated collision behavior may be added to Anchored objects in Physical Mode, and to NonAnchored objects in Geometric mode.
  • runLocally may automatically request network ownership
  • Non-anchored objects may throw on release (instead of merely dropping) even in Geometric mode
  • Other bug fixes reported in beta feedback are coming; they will not likely effect gameplay

If you are comfortable with all of that, here is a link to request that we turn on DragDetectors in your published game:

P.S. We have enabled DragDetectors in “DragDetectors TestWorld 1” and “DragDetectors TestWorld 2

32 Likes

Yes! Thank you, this would be an awesome addition to our new game!

4 Likes

i have tried it with publich but he reset the axis by restart

and the eroor is this
Screenshot 2023-06-13 12.35.55

2 Likes

Add and Remove Constraint API signature will change and may break my code

Which code can it break scripts for things for the game or only drag detector script

  • DragDetectors TestWorld 1 - Roblox nice things made i have test itmin mobile and it work the second worldx have I’m not tested yet

  • In my Obby would i use my creations it are levels what i publiche later because there already levels before they not publiche but i made an teleport screen so people can test that levels and in the future you can play

how you made in the form that you must select things

I has worked with Google forms in the past for that people bugs can report to me via a broke site but I’m never saw that that can (i has not can use them because me account store was full ) you cannot fill in it but maybe I will made a new on other acc and set a link in my cominity but idk of i can people sent to it and I can tell jow they come there

EDIT i have test the second world but where are the towers for

4 Likes

i’m pretty confused by your saving issue. But you’re making a change to the data model so it has to save when you publish. It’s hard for me to believe this is a bug unless there is some kind of script resetting this axis somewhere. I have 2 more suggestions: First, rename the DragDetector so that you are 100% certain you are looking at the same one. I see many things with the same name so it’s hard to be sure that we’re looking at the same object before and after. Second, there is a script inside the DragDetector. What’s in that script? Is it possible that this script, or another in your game, is updating or rebuilding your DragDetector?

As for the scripting error:
“X cannot be assigned to” indicates that you probably have code like:
dragDetector.Axis.X = 0
dragDetector.Axis.Y = 0
dragDetector.Axis.Z = 1

But this is not legal lua code. You cannot assign the elements of a vector individually. Instead you need:
dragDetector.Axis = Vector3.new(0,0,1)

4 Likes

Sorry, I was not clear about what will change with the new constraint API.
The ONLY things that will break are that if you have a script that calls DragDetector:AddConstraintFunction or DragDetector:RemoveConstraintFunction.
EVERYTHING else will continue to work in all scripts.

For those curious, the upcoming change is just to simplify the calls. You won’t have to name your function. So instead of:
OLD:
dragDetector:AddConstraintFunction(1, “MyFunction”, function()
– some code
end)
dragDetector:RemoveConstraintFunction(“MyFunction”)

NEW
local connection = dragDetector:AddConstraintFunction(1, function()
– some code
end)
connection:Disconnect()

2 Likes

As for your other comments:
On mobile, dragging should not move the camera when you click and drag a dragDetector. It should only move the camera if you click and drag an area off the DragDetector, or if you use the thumbstick.
If you have a different result, can you post a video somehow? or very clearly describe what you are doing and what you see?

As for the form…I don’t know how we made it so that you must select things! @Urukeli made it so I need to let him answer your question.

2 Likes

On mobile camera should not move if drag detector is activated.
Character would move, but camera should gets disabled by dragging in test place. I just tried on
TestWorld 1

P.S. @foodeggs7 Google form - you can Click three vertical dots near Required switch in the bottom of the question and select “Answer Validation”.

2 Likes

I also tried Test World 1 on my phone and it worked as expected, So @foodeggs7 if you are getting simultaneous drags and camera moves please give us some details: type of device, whether you are in first person mode, which demo you are dragging, where you are clicking on screen, etc. And if you can do it, a video showing the incorrect behavior?

2 Likes

I tested it but i think I’m not picking up the drag detectors because the sun was into my screen shining so I’m not picked up it correct but i tested it again and it work

4 Likes

I activated DragDetectors for submitted places. If it doesn’t work for you place please reply here. We also added a verification step to the form to avoid misunderstandings.

6 Likes

@YasuYoshida , thanks again for this great feedback and information.
I’ve had a chance to look through all of it and here’s the result:

Mysterious DragStyleFunction Parameter

Oops! We documented how to add/remove/set functions but did not document the arguments to those functions! I will update the documentation and post here when it’s fixed.
For now:
constraint functions have:
1 input: CFrame proposedMotionInReferenceFrame (the motion that would be applied to the pivot relative to the referenceFrame if you didn’t constrain)
output: CFrame newMotionInReferenceFrame (the motion that should be used instead)
customDragStyleFunctions have:
1 input: the cursorRay in worldspace. It’s a ray from the viewpoint in the direction of the cursor.
1 output: CFrame desiredWorldspaceCFrame (the desired orientation and position for your object)

if you haven’t found it yet, there are examples of using the cursor in the customDragStyle in “DragDetectors Test World 1” and “DragDetectors Test World 2”: search for “followTheCursor” in the scripts

Missing AlignOrientation for Scriptable DragStyle

You are correct! Great find; we will fix. It’s also the case for 6DOF in VR (which you get with “BestForDevice” with VR input)

Stuttering with Geometric Dragging in First Person

I don’t think this is a mismatch between dragger and camera; if so, then when you stop moving the camera, the object would not return to the same place relative to the cursor; it would be out of register. I’ve seen that before. Rather, I think the issue is that rendering and camera moves happen at a faster rate than the drag/UI events. For every few frames rendered, there may be only one drag. So when you move the camera while you’re dragging, you get the same effect whether you runLocally or not. The blue box in this video is running on server with no scripts. The red box uses your script. The stuttering occurs for both whether you are running or turning your head. I’m not sure there’s much to do about this unless we could do some kind of automatic rendering interpolation. This would be an extra project for later but I’ll make a note of it.

Unexpected Positioning

This demo looks different from what you have above because the camera is not moving so you’ve got motion but not first person. Anyhow, I made something similar that also showed what is probably the same bug. The good news is, there is a fix for the bug I am seeing that should go live late next week. When it does, I’ll ask you to test this. If the problem is still there I will ask you perhaps for your world file (or send it today if you want me to confirm now).

Constraints Remaining after Dying

A change that is coming next week will make it so that you will not see added Attachment and Constraint objects in the data model. The behavior will be the same except we are using internal APIs so as not to edit the data model in this way just to perform a drag.
Either way, we need to clean up in certain cases. We’re handling when players LEAVE the game, but not when they die! New bug for us to fix. Thanks so much!

5 Likes

Suttering with Geometric Dragging in First Person

I never realized that it wasn’t constantly updating when using a DragDetector. In fact, now that you mention that, I’ve noticed instances where the object doesn’t immediately go to the desired location until it updates. This can look weird in certain scenarios like this one:

As you can see in the video, I start dragging it, but it only slightly moves to an irrelevant location. Once I trigger an update by moving my camera/mouse, then it goes to the correct location.

Unexpected Positioning

It’s actually the same exact setup. I have a ScreenGui in StarterPlayerGui that has a TextButton with ModalEnabled. When I do this, it allows me to freely move my mouse in first person. I can hold the right mouse button down to move my camera with this setup. That’s what the “Stuttering with Geometric Dragging in First Person” video showed. The “Unexpected Positioning” video only used the aspect of moving your mouse in first person and not rotating the camera. I’m not sure if that makes sense. It’s easier to understand if you take a look at the place file below.

Here’s a place file that contains the exact same stuff used in the videos from my previous post:

DragDetectorExamples.rbxl (57.5 KB)

It also contains the ScreenGui with a ModalEnabled TextButton that I mentioned earlier.

Constraints Remaining after Dying

I really like seeing how the constraints are affecting the object and where the attachments are located when Constraint Details is turned on (that’s what I was using for the Unexpected Positioning video). I hope that aspect of them remain. If not, something like those would definitely be on my list of useful stuff for debugging DragDetectors.

Thanks for the reply. I know it can take quite a bit of time to formulate one.

4 Likes

What contain the script i has the script later added it’s the script what has an error

i have changed the name from draggdetector but he still reset

Im busy with set the drag detector in my onby i have used your text for explaining what drag detectors are is that ok

and i have now publice it in my obby but it dont save the axis i have before publice the axis changed

Video Canot uploaden

I have in the yellow brick set an kill script so you Canot jump over it and om it invisible walls

For everyone who want to test it in my Obby click then here

1 Like

Suttering with Geometric Dragging in First Person

First, off, regarding the stuttering in Geometric mode:
I talked with some of the engineers and my assumption above. may be incorrect; it’s possible that we can get a better result by coordinating our changes with work we do in a PreRender callback. We will be researching this, although we may tackle it after the other more functional issues are addressed.
As for your your new physics example:
Two things are happening here.
The first is that on mouseDown:
Our general contract is that on mouseDown, the object should not move at all; and if applyToCenterOfMass is true then on mouseDown the centerOfMass will be moved to the cursor.
However, currently there is a bug that often moves the object to a funny spot on mouseDown; I think you were seeing this in your earlier example “UnexpectedPositioning.” A fix for this is coming next week.

The second is that the object does not go in front of the player until the mouse moves. This is because your custom drag style function is only called once you move the mouse; which is correct. If you want it to fly there immediately you will need to take action onMouseDown.
All this is different than the stuttering issue that happens when the camera is changing more often than the dragging occurs.

Unexpected Positioning

Thanks. I played with your world file a bit, and I’m pretty sure that this will behave the way you desire once we have [a] next week’s bug fixes and [b] creation of the AlignOrientation constraint that is currently missing. But we’ll confirm as these changes roll out.

Constraints Remaining after Dying

I understand it’s convenient for debugging, but it is best for us to make as few changes to the data model as possible that are side-effects of dragging, even if only temporary. We are always going to need to change ‘anchored’ between true and false. But we have alternatives to constraints to keep things cleaner.
We can add debug tools to help you inspect or visualize the constraints later.

Thanks for your replies as well. You are giving us information that will help hundreds of people after you have a better and easier time.

4 Likes