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

Why is math.pi important for rotating Parts etc...?

Asked by 9 years ago

For example in this script - I cant understand why he needs math.pi. local playa=game.Players.LocalPlayer;

script.Parent.Selected:connect(function(mouse)
    while Wait() do
    local weld=playa.Character.Torso["Left Shoulder"];
    --[[
        p0=part0.CFrame
        c0=c0
        p1=part1.CFrame
        c1=c1

        p1*c1 == p0*c0
        c1 == p1:inverse()*p0*c0
        c0 == p0:inverse()*p1*c1
    --]]
    local desired_p1=CFrame.new(--the CFrame that we want the arm to be at
                (weld.Part0.CFrame*CFrame.new(-1,1,0)).p,--the position we want
                mouse.hit.p--look at the mouse
            )*
            CFrame.Angles(math.pi/2,0,0);--rotate it so that the hand points that way
    weld.C0=CFrame.new();--set C0 to identity matrix so it is out of the equation
    weld.C1=desired_p1:inverse()*weld.Part0.CFrame;--same equation as shown above
end end
)

-- Also can someone explain how each line of this scripts work with a n explantion on how the math works in this script.

1 answer

Log in to vote
2
Answered by
davness 376 Moderation Voter
9 years ago

It's simple. CFrame.Angles uses radians and not degrees

The formula is the following: 1 degree = math.pi/180 radians or else math.pi radians = 180 degrees

So, math.pi/2 is the same of 90 degrees.

If you run a command like this

workspace.Part.CFrame = CFrame.new(0,0,0) *CFrame.Angles(math.pi/2,0,0)

And then print it's rotation, you will get the follow:

90,0,-0

0
Why does 90 degrees work for rotating the arm as well. Blockeus 68 — 9y
0
you can change the Rotation property, using Vector3.new and accepting degrees davness 376 — 9y
0
what does line 19 and 20 do. Blockeus 68 — 9y
Ad

Answer this question