Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
5

How do I weld two objects together without them touching?

Asked by 10 years ago

Excuse me, I am attempting to weld objects to an engine without them being touching, anyway to do that ( The objects are cframed and unanchored ) Please do not reply with any links concerning wiki.roblox or lualearners because I have tried both.

4 answers

Log in to vote
8
Answered by
MrNicNac 855 Moderation Voter
10 years ago

Here is an easy function to weld two objects exactly where they are (they will not touch):

function Weld(p1, p2)
    local w = Instance.new("Weld", game.JointsService); -- create the weld and correctly store it in the JointsService
    w.C1 = p1.CFrame:toObjectSpace(p2.CFrame)
    w.Part0 = p2 -- Set the main part 
    w.Part1 = p1 -- Set the joined part
end

Weld(Workspace.Part1, Workspace.Part2) -- Call the function to weld the two objects

EDIT: What you're probably most confused about is this line:

w.C1 = p1.CFrame:toObjectSpace(p2.CFrame)

The C1 is the "negative push" away from where the parts are joined. So we want to make sure the two parts stay exactly where they are, right? Welds work in object-space coordinates (so do all joints). Remember that.

All this line does is set the part getting joined to be in the object-space of the second part. This way they will stay the same distance away from each other (in their object-space) when joined.

0
Could you possible break that down using comments ( IGN comments after each line ) I am not quite the best at understanding things. Lucideum 15 — 10y
0
Sure; but if you really want to understand how they work, you will need to learn about the concepts of world-spaces and object-spaces. MrNicNac 855 — 10y
Ad
Log in to vote
0
Answered by 10 years ago

You can just use C0 and C1 like you would supposing that they were touching. If you want to weld two parts together in the exact manner they are currently, you can do this:

weld.C1=weld.Part1.CFrame:toObjectSpace(weld.Part0.CFrame)

What that will do is set the C1 what you need to have it look the same. Assume Part0 and Part1 are set already, and C0 is the default.

0
It is not good practice to use this format of setting the C1 to the object-space of the main part for new work. MrNicNac 855 — 10y
0
No I do not, I do not understand how to set that. Lucideum 15 — 10y
0
I've updated my answer accordingly and given your answer an upvote, as it is more complete. TheLuaWeaver 301 — 10y
0
How noble of you. MrNicNac 855 — 10y
Log in to vote
-2
Answered by 10 years ago

THANK YOU!!!!

0
Please select an answer by clicking "Accept Answer" below the poster's avatar and not posting an "answer" to say thanks. MrNicNac 855 — 10y
Log in to vote
-2
Answered by 10 years ago

Instance.new("Weld")

Answer this question