Drag Detectors Help - Moving a Model in the opposite Direction

Hey Developers! I decided to mess around with this New Beta in my projects Called Drag Detectors Considering that it would be useful for the project I am making.

Now I am making a sliding double door. In other words, when you move the door, I want the second door to slide, but on the opposite side to cause natural Movement

In other words. This is what I have right now:

You can see that there is one door (right door) moving to the right in a open position, before, moving to left to be closed.

How can I make it, so the other door (left door) is moving in left direction, while the right door is moving right? And same with closing a door, when the player drags it to close the door, how can I make so the left door is moving right, and right door is moving left when closing a door…

Does it make sense? How can I do something like this? Any ideas?

3 Likes

so like both doors move according to what the selected door is being dragged to?

1 Like

Yes. If one door is sliding to be opened, the other door is moving to be opened too.

Images for what I mean:


(Green arrows shows the sliding action of the doors for the open position)


(Red arrows shows the sliding action of the doors for the Closed position)

2 Likes

thank you for the visualizaiton :]

  • for your ease, handle this all in a script. make sure you have an attachment or invisible part or vector3 variable that’ll represent the center of both doors, as a starting position. reffering to it as startingPos

  • have both of your drag detectors instantiated and have a function dedicated to when either of them are activated, so there are 2 functions. comment label them right and left since the internals of both are similar.

  • setup a TweenInfo and Tween object using TweenService | Documentation - Roblox Creator Hub
    referring to this as tweenObj. Make sure for easing you have it on Sine for smooth movements.

  • for one of the functions (we’ll exemplify with the right door function) you are going to refer to the LEFT door and tweenObj:Play() the Vector3 of the RIGHT doors Vector3 subtracted by the startingPos. If it doesnt work properly or it just goes the same way as the right door then I have it backwards. Do the same for the other function (so the left door) and youd refer to the RIGHT doors’ Vector3.

  • the reason why having 2 functions is a better play is because having a runservice.RenderStepped function running the Vector3 of the doors is a little overkill and can be a logic nightmare sometimes, also considering that were using drag detectors so having values being changed per frame can be hard to deal with.

3 Likes

Hey, Thanks you for you reply. A couple of Questions, as I am New(ish) to Drag Detectors and there isn’t much resources on them besides the Docs.

I know you mentioned the TweenService. The issue is that these doors are models and not a BasePart, meaning that I will have to Use PivotTo() and GetPivot(). Meaning if I were going down that route how would I go about the smoothness of “The slide animation”.

Do I really Need to Tween it with the DragContinue Event? If so Do I have to worry about limits (How many times it fires) / How can I get the time to Tween it to the position (If I tweened it). My goal is to have it nice and smooth in other words, Not when the Dragging ends it updates, rather it updates while the user is Dragging it (All Drag dectectors are disabled when one is being moved).


Thanks for your help so far!

1 Like

I wrote A Little function as a Test:

local function SlideDoors(DoorNeededToSlide, DraggedDoor, MiddlePoint)
	DoorNeededToSlide:PivotTo(CFrame.new(DraggedDoor:GetPivot().Position - MiddlePoint.Position )) --Issue is here with Position
end

game.Workspace.RepellingDoors.LeftDoor2.DragDetector.DragContinue:Connect(function()
	SlideDoors(game.Workspace.RepellingDoors.LeftDoor1, game.Workspace.RepellingDoors.LeftDoor2, game.Workspace.TestMiddlePoint)
end)

Its a starting point, and I mean It is Sliding, but it does it goes to the origin of the game… Stilling trying stuff out.

1 Like

I’m think I’m getting closer with this:

local function SlideDoors(DoorNeededToSlide, DraggedDoor, MiddlePoint)
	DoorNeededToSlide:PivotTo(  CFrame.new( Vector3.new(DraggedDoor:GetPivot().Position.X, DraggedDoor:GetPivot().Position.Y, DraggedDoor:GetPivot().Position.Z + (DraggedDoor:GetPivot().Position.Z - MiddlePoint.Position.Z) )))
end

game.Workspace.RepellingDoors.LeftDoor2.DragDetector.DragContinue:Connect(function()
	SlideDoors(game.Workspace.RepellingDoors.LeftDoor1, game.Workspace.RepellingDoors.LeftDoor2, game.Workspace.TestMiddlePoint)
end)

Cframes and Vectors aren’t easily understood to me lol…

1 Like

This is gonna sound stupid since I’ve literally never touched a dragdetector in my life, but from what you’re telling me it uses cframes and stuff like that, so if the right door works fine you can probably make the position the right door moves to a variable, then use it negative

so basically negate the position of the working door as a baseline

2 Likes

All you Need to know basically about DragDetectors is that DragContinue Fires when the Drag detector is fired and moving (changing it’s position). My Drag detector is stuck within an Axis to move from.

How would I " negate the position of the working door as a baseline ". I know a little about how CFrames works, I have worked with them a Tad, but I’ll confused on how I would get it haha.

If it Helps, the variables in My function Are:

DoorNeededToSlide - This is the door that doesn’t move with the Drag dectector
DraggedDoor - This is the dragged door from the Drag dectector
MiddlePoint - This is this part, in the middle of the 2 Doors
image

Any ideas on how I could do what your talking about?

1 Like

just use -cframe, its pretty much the same thing as inversing a cframe (from my knowledge)

local cframe = CFrame.new(50, 0, 17)
print(-cframe) -- should return -50, 0, -17
cframe = CFrame.new(-50, 0, 17)
print(-cframe) -- should return 50, 0, -17

(replace -cframe with cframe:Inverse())
this is what should happen from my knowledge. putting - INSIDE the cframe statement of course changes a single axis, the - of a cframe should be its inverse

so just use the negative cframe/position of the way you’re moving your door

This is not possible, to inverse a cframe you need to use :Inverse()

1 Like

I got an Error with "attempt to perform arithmetic (unm) on CFrame "

This was my code I tried.

local cframe = DraggedDoor:GetPivot()
	DoorNeededToSlide:PivotTo(-cframe)

oh yeah do what he said, sorry i’m pretty dumb. It’s because i use negative positions that I thought it was possible. @OfficialPogCat

Yea it went farrrrr away

image

My code:

local cframe : CFrame = DraggedDoor:GetPivot()
DoorNeededToSlide:PivotTo(cframe:Inverse())

nuh uh not like that, bring your working code back, then cut everything that was inside the PivotTo and make that a cframe, then do the inverse logic you need

We flipped! Still farr away

Using this code above & Inverse it just doing this:

	local cframe : CFrame = CFrame.new( Vector3.new(DraggedDoor:GetPivot().Position.X, DraggedDoor:GetPivot().Position.Y, DraggedDoor:GetPivot().Position.Z + (DraggedDoor:GetPivot().Position.Z - MiddlePoint.Position.Z) ))
	DoorNeededToSlide:PivotTo(cframe:Inverse())

No, you pivot the working door to the same cframe as when it was working. You pivot the opposite door to the inverse of that cframe. I’ll try to make a test demo in studio.

EDIT: YOU MAY HAVE TO USE CURSORRAY TO POSITION THE DOORS

This would only work if the middle point was at at 0, 0, 0.
nvm im dumb.

Would it be easier if I used the middle part to find how much I would need to move it by?

Aka, find the distance of Green line and move the left door By the light blue amount?

If this could work, how could I caculate it?

local door = workspace:WaitForChild("Door")

local originalOtherDoorX = workspace.OtherDoor.CFrame.X

door.DragDetector.DragContinue:Connect(function()
	workspace.OtherDoor.CFrame = CFrame.new(originalOtherDoorX - door.DragDetector.DragFrame.X, workspace.OtherDoor.CFrame.Y, workspace.OtherDoor.CFrame.Z)
end)

I’ve created the effect you want to achieve

sliding doors.rbxl (55.2 KB)

4 Likes