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

Why is CFame.Angles not rotating the object the full 90 degrees?

Asked by 5 years ago

I have a script that is supposed to weld a piece of metal plating to the players arm & it is supposed to rotate it depending on if it is welded to the right, bottom, front & so on.

But when I run the script it doesn't rotate it the full ninety degrees & it rotates it something more like 45 degrees.

Here is the code:

_G.LimbPlatingWeldEnable = function (LR, FB, TB, Rot, Prt0, Prt1)
    if Prt1:FindFirstChild("weld") == nil then
        Prt1.CFrame = Prt0.CFrame * CFrame.new(LR * 0.6, TB * 0.6, FB * -0.6) * CFrame.Angles( LR * 0, FB * 90, TB * 90)
        weld = Instance.new("Weld")
        weld.Part0 = Prt0
        weld.C0 = Prt0.CFrame:Inverse()
        weld.Part1 = Prt1
        weld.C1 = Prt1.CFrame:Inverse()
        weld.Parent = Prt1
        weld.Parent.Anchored = false
        weld.Parent.CanCollide = false
    end
end

LR is if the plate is to the left or right, 1 for right, -1 for left. FB is if the plate is to the front or back, 1 for front, -1 for back. TB is if the plate is on top or on the bottom, 1 for top, -1 for bottom. Prt0 is the players lower right arm. Prt1 is the metal plate.

1 answer

Log in to vote
1
Answered by 5 years ago

You need to use math.rad when handling angles like that. https://www.robloxdev.com/articles/Lua-Libraries/math#math.rad So, you would do the following with the function:

_G.LimbPlatingWeldEnable = function (LR, FB, TB, Rot, Prt0, Prt1)
    if Prt1:FindFirstChild("weld") == nil then
        Prt1.CFrame = Prt0.CFrame * CFrame.new(LR * 0.6, TB * 0.6, FB * -0.6) * CFrame.Angles( LR * 0, math.rad(FB * 90), math.rad(TB * 90))
        weld = Instance.new("Weld")
        weld.Part0 = Prt0
        weld.C0 = Prt0.CFrame:Inverse()
        weld.Part1 = Prt1
        weld.C1 = Prt1.CFrame:Inverse()
        weld.Parent = Prt1
        weld.Parent.Anchored = false
        weld.Parent.CanCollide = false
    end
end

Good luck! Accept my answer if it helped you out so I know, and leave me a comment if you don't understand something or still need help.

Ad

Answer this question