here i have 2 parts Red and Blue
and i want Red to snap to Blue’s position without changing its orientation
right now i have just this Weld
right now, Red snaps to Blue’s position and orientation (which i dont want)
how would i achieve this with code? soo Red’s orientation can be whatever and still dont change after snapping to Blue’s position
any help would be appreciated!
I am not good with CFrame
s, but if I were you, I wouldn’t use Welds
to weld two parts together, instead I would use WeldConstraint
as it is more simplified because you do not have to deal with CFrame
operations.
If you were to code it, then you can just do this:
local weldCons = Instance.new("WeldConstraint")
weldCons.Part0 = script.Parent
weldCons.Part1 = workspace.Blue
weldCons.Parent = script.Parent
Keep in mind, you must change the CFrame
of either part so that the whole assembly moves together.
1 Like
this does not snap Red to Blue tho?
Nope, but how do you want them to snap? Like, do you want the two parts to be touching each other when the script runs regardless of the parts’ orientation?
If that’s the case, then you probably need some other code to teleport one part to the other, and then do multiple checks to ensure the parts are not touching each other until it achieves your desired “snapping pattern”.
thats why i wanted to use Weld cause it snaps part1 to some offset centered on part0, and i wanted someway to use that while keeping part1’s (Red) orientation
Well you’d have to learn how to work with CFrame
s, I can’t teach everything about it. This is all I can help.
My solution:
local weld = Instance.new("Weld")
weld.C0 = workspace.Blue.CFrame:Inverse()
weld.C1 = workspace.Red.CFrame:Inverse()
weld.Parent = workspace.Blue
weld.Part0 = workspace.Blue
weld.Part1 = workspace.Red