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

Welding help? Orientation Problem.

Asked by 6 years ago

I have created a Welding script which welds an armor in Server storage(cloned) to my upper torso. Now the armor has many parts and a middle upper torso. After setting the upper torso, when I go for other parts to be welded they are not perfectly oriented. So can anyone tell me what is that I am doing wrong? Note : Middle is the real Upper Torso part that needs to be welded and Union1 is an extra detail that I created.

local tool = script.Parent
local player = game.Players.LocalPlayer
local char = player.Character
local debounce = false
tool.Equipped:Connect(function(mouse)
    mouse.KeyDown:Connect(function(key)
        if key == "h" then
            if not debounce then
                debounce = true
                char.UpperTorso.Transparency = 1
                --Upper Torso
                --Middle
                local uppertorsoweld = Instance.new("Weld")
                local uppertorso = game.ServerStorage.IronManSuit.UpperTorso2.Middle:Clone()
                uppertorso.CFrame = char.UpperTorso.CFrame
                uppertorso.Parent = script.Parent
                uppertorsoweld.Part0 = char.UpperTorso
                uppertorsoweld.C0 = char.UpperTorso.CFrame:Inverse()
                uppertorsoweld.Part1 = uppertorso
                uppertorsoweld.C1 = uppertorso.CFrame:Inverse()
                uppertorsoweld.Parent = script.Parent
                -- Union 1
                local uppertorso1weld = Instance.new("Weld")
                local uppertorso1 = game.ServerStorage.IronManSuit.UpperTorso2.Union1:Clone()
                uppertorso1.CFrame = uppertorso.CFrame*CFrame.new(0,0.27,-0.06)
                uppertorso1.Parent = script.Parent
                uppertorso1weld.Part0 = uppertorso
                uppertorso1weld.C0 = uppertorso.CFrame:Inverse()
                uppertorso1weld.Part1 = uppertorso1
                uppertorso1weld.C1 = uppertorso1.CFrame:Inverse()
                uppertorso1weld.Parent = script.Parent
                wait(5)
                debounce = false
            end
        end
    end)
end)

1 answer

Log in to vote
0
Answered by
LeadRDRK 437 Moderation Voter
6 years ago
Edited 6 years ago

Your weld needed to be re-orientated. Basically, when you weld two parts together, they will return to their "perfect orientation" of 0, 0, 0. So, when you weld the Torso to the armor, they resets their orientation, the Torso is unaffected because the default orientation of it is identical to what the weld trying to set it to. The armor? Maybe not. So in order to re-orientate it, you need to use CFrame.Angles

Example:

Weld.C1 = CFrame.Angles(0,15,0) --rotate Part1 15 Y radians

And that’s basically how it works. But in your script you also use inverse, so we also need to combine those two together, using the * operator:

Weld.C1 = Part1.CFrame:inverse() * CFrame.Angles(0,15,0) --inverse the cframe AND rotate Part1 15 Y radians

And that’s all done. You should be able to rotate your shield now. Just change the angles to the ones you desire.

NOTICE: CFrame.Angles uses RADIANS, not DEGREES, be sure to use the correct values.

0
Ok thx. halfvedantpandya1234 6 — 6y
0
So like 3.14 radians is 180 Degrees right? halfvedantpandya1234 6 — 6y
0
It moves the part instead of orienting it. halfvedantpandya1234 6 — 6y
0
hmm, should not be doing that. try it w/o inverse LeadRDRK 437 — 6y
View all comments (3 more)
0
also try each axis to see if they also moves LeadRDRK 437 — 6y
0
ok halfvedantpandya1234 6 — 6y
0
Nope. This time w/o inverse the weld is not created at all halfvedantpandya1234 6 — 6y
Ad

Answer this question