Welds are a joint that rigidly holds their parent part and another part in a fixed position relative to each other, such as holding one part 2 units to the right of another part. They can be used in places where parts need to be held together at odd angles, but still be able to move (meaning they will not work with Anchored parts), such as for a vehicle.
The weld object is placed inside of a part, and a property is set to determine which other part should be welded to the original part. Then two CFrames, the C0 and the C1, tell the weld how the parts should be placed.
|Part0||This property of a weld is an Object, it must always be set to the part the weld is in for the weld to work|
|Part1||This property of a weld is an object and tells is which part it should be attaching its parent to|
|C0||determines how the [offset point] should be attached to the Part0|
|C1||determines how the Part1 should be attached to the [offset point]|
Since C0 and C1 are both offsets this equation means that the weld must satisfy the condition that each part CFrame multiplied by its respective offset must end up being equal to each other. This looks like this:
Where blue is the C0 offset and red is C1 offset.
Figuring out what to set the C0 and C1 to is a bit finicky, but one you get good at it, it can go quite quickly. For Welds, you dont have to worry about the C1, it's automaticaly set to a "unit" or unrotated CFrame, you only have to deal with C1 when working with motors, so ignore it for now. The C0 will tell the weld how it should attatch itself to the other part, eg.
[weld].C0 = CFrame.new(0, 2, 0)
This tells the weld that it should hold the part1 in a position 2 studs above the part0, simple eh?
To rotate the CFrame you must use the following command, which is case sensitive.
CFrame.fromEulerAnglesXYZ(#, #, #)
This is used as follows:
This tells the weld to attach the part1, two studs above the part0 AND rotate the part1 by 180 degrees relative to the part0
You use math.pi, as the number to rotate by, use it in the following fashion :
Now that you know how to use the basics of a weld, here's how you put it all together. Here's an example:
Let's say that this is in a script, in a vehicle:
local pln = script.Parent local w = Instance.new("ManualWeld") w.Parent = pln w.Part0 = pln.Engine w.Part1 = pln.Wing1 w.C0 = CFrame.new(0, 0, 6)*CFrame.new(0, -math.pi/5, 0)
Sometimes, you want to just weld together two parts in their current positions, so that they remain in the same relative positions. This takes just a basic understanding of CFrame math and welds. As previously mentioned,
And understanding that
cancels out, we can apply some basic algebra
So this means we can do :
You can then do the following to weld two parts together: