AlignPosition isn't working properly when dragging parts

I am attempting to make a part dragging script using the AlignPosition constraint. When dragging the part, you can see in the video I’ve included that the constraint moves to the desired position, but the part does not follow immediately, rather it has a delay.

Video here:

I’ve attempted to adjust the settings for the constraint, such as MaxForce and Responsiveness, but it does not change the issue.

Here is a snippet of the code that deals with the constraint and mouse movement:

for i, value in pairs(partsFolder:GetChildren()) do

		if down == true and target == value then
			
			currentTarget = value
			alignPos = value.AlignPosition
			alignPos.Enabled = true
			targetPos = head.Position + (mouse.Hit.Position - head.Position).Unit * dist
			alignPos.Position = Vector3.new(targetPos.X, targetPos.Y, targetPos.Z)

I would appreciate any help with this, whether it is an issue with my scripting or the properties of the constraint.

Thanks to this post I realized that you’re supposed to update the attachment’s WorldPosition, not just the target position of AlignPosition. Everything is working smoothly now. If anyone is reading this later on, this is how I updated the code to get it working correctly.

for i, value in pairs(partsFolder:GetChildren()) do

		if down == true and target == value then
			
			currentTarget = value
			alignPos = value.AlignPosition
			attach = value.Attachment0
			alignPos.Enabled = true
			targetPos = head.Position + (mouse.Hit.Position - head.Position).Unit * dist
			alignPos.Position = Vector3.new(targetPos.X, targetPos.Y, targetPos.Z)
			attach.WorldPosition = alignPos.Position

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