local Debounce = false
local Orientation = BuildPreview.PrimaryPart.CFrame - BuildPreview.PrimaryPart.Position
BuildPreview:SetPrimaryPartCFrame(Orientation + Mouse.Hit.Position)
for _,CurrentAttachment in pairs(BuildPreview.BoundingBox:GetChildren()) do
for _,OtherAttachment in pairs(game:GetService("CollectionService"):GetTagged("BuildAttachment")) do
if CurrentAttachment.Parent ~= OtherAttachment.Parent and OtherAttachment:IsDescendantOf(game.Workspace) then
if (CurrentAttachment.WorldPosition - OtherAttachment.WorldPosition).Magnitude < 1 and Debounce == false then
Debounce = true
BuildPreview:SetPrimaryPartCFrame(CFrame.new(OtherAttachment.WorldPosition))
end
end
end
end
This script does this:
But I want the two attachments to line up. Instead what I have right now is just setting the builds position to the other attachments position
part1.CFrame * C1 == Part0.CFrame * C0
--C1 and C0 are CFrame offsets, the same as attachments CFrame as attachments CFrame is relative to the parent
part1.CFrame * part1.Attachment.CFrame = Part0.CFrame * part0.Attachment.CFrame
--Solve for part1 which is the one thats being dragged
part1.CFrame = Part0.CFrame * part0.Attachment.CFrame*part1.Attachment.CFrame:Inverse()
--Up to you to find the two attachments closest to each other
AllignPosition and others of the sort will not work because the parts need to be anchored, and with the equasion that you provided to me, I can’t use CFrames for reasons. Is there any way I could calculate it with just Vector3’s?
Why not use CFrames? I see the code up there already uses CFrames.
I believe It can be adjust it like this:
local part1FormulaCF = OtherAttachment.Parent.CFrame*OtherAttachment.CFrame*CurrentAttachment.CFrame:Inverse()
BuildPreview:SetPrimaryPartCFrame(part1FormulaCF)