Aligning dragging part to player

so i decided to make a dragging system using a dragdetector attached to a part and an alignposition constraint to make it follow the player when dragging said part.
i have implemented a network ownership changing system that uses the SetNetworkOwner() function to change the physics calculation to the client of the player dragging the part, and switch it back to server physics calculation when the no player is dragging said part.

i came across an issue with the alignposition constraint where if i drag the part, the part would move to the player and thrust them away like this:

here’s what does the part look like in the explorer:
Screenshot 2025-04-29 at 5.54.12 PM

here’s replicated storage and serverscriptservice (run config is part of a run script):

and here’s all the code that’s within my scripts:

the eventsender script:

local repstorage = game.ReplicatedStorage
local event_netown = repstorage.NetOwnerShip
local dragdet = script.Parent
local grabbedpart = script.Parent.Parent
local alignpos = grabbedpart.AlignPosition

dragdet.DragStart:Connect(function(draggingplayer: Player)
	event_netown:Fire(draggingplayer, grabbedpart)
	task.wait()
	
	local plrchar = draggingplayer.Character or draggingplayer.CharacterAdded:Wait()
	local plrrootpart = plrchar:FindFirstChild("Humanoid").RootPart
	local plrattachment = plrrootpart:FindFirstChild("GrabAttachment")
	
	alignpos.Attachment1 = plrattachment
end)

dragdet.DragEnd:Connect(function(draggingplayer: Player)
	event_netown:Fire(draggingplayer, grabbedpart)
	task.wait()
	
	alignpos.Attachment1 = nil
end)

the createrootattachment script:

local players = game.Players

players.PlayerAdded:Connect(function(newplayer: Player) 
	local plrcharacter = newplayer.Character or newplayer.CharacterAdded:Wait()
	local plrchar_root = plrcharacter:WaitForChild("HumanoidRootPart")
	
	local plrattachment = Instance.new("Attachment")
	plrattachment.Parent = plrchar_root
	plrattachment.Name = "GrabAttachment"
end)

and here’s the network ownership script:

local repstorage = game.ReplicatedStorage
local event_netown = repstorage.NetOwnerShip

event_netown.Event:Connect(function(grabbingplayer, grabbedpart)
	if grabbedpart:GetNetworkOwner() ~= grabbingplayer then
		grabbedpart:SetNetworkOwner(grabbingplayer)
		print(grabbingplayer.Name .. " now calculates the physics of " .. grabbedpart.Name)
	else
		grabbedpart:SetNetworkOwner(nil)
		print("the server now calculates the physics of " .. grabbedpart.Name)
	end
end)

i hope what i provided was enough for you to help me fix the throwing issue.
p.s: i do know that the alignposition constraint defaults to the center of the attachment.

1 Like

Have you tried using collision groups to filter it from colliding with undesirable parts? You could use it so it doesn’t fling character(s).

i mean this is not what i want. what i intend is for the part to stay in its place and move whenever the player moves, but still move independently when the player drags it.

I am still waiting for a fix lol.

It’s probably because AlignPosition is applying too much force too suddenly. It’s trying to snap the part directly to the player’s attachment, so the physics goes crazy for a second.

A few things you can try:

  • Set AlignPosition.RigidityEnabled = true so it treats it more like a solid link and doesn’t push the character as hard
  • Lower AlignPosition.MaxForce and Responsiveness so it doesn’t try to move too fast
  • Make sure the alignment is already pretty close when it’s applied since big gaps between the part and the attachment can cause large physics impulses
  • You might also want to disable collisions between the part and the player using a CollisionGroup

If you don’t want the part to move when not being dragged and only move when the player drags it, you might want to keep it anchored or just remove the AlignPosition entirely until DragStart fires and then create and configure the constraint during the drag only.

Let me know if that helps.

so what i want is the part to follow the player when moving, like when the dragdetector is set to translateplane, but instead applied to translateviewplane

Just set the UIDragDetector’s DragStyle to TranslateViewPlane instead of TranslatePlane. You still need to make sure your AlignPosition target is positioned relative to the view direction (like placing the attachment in front of the camera).

i think i implemented a janky fix by using translateplaneorline, but thanks

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.