user402464
user402464

Reputation: 1

How do I CFrame parts?

I've heard that you can tilt a part by a precise amount using the .CFrame property. However, I'm unclear on how to use it. The following code does not work:

Workspace.Part.CFrame = CFrame.new(90,0,45)

It is not rotating the part by 90 degrees and 45 degrees. What am I doing wrong?

Upvotes: 0

Views: 1108

Answers (5)

tusKOr661
tusKOr661

Reputation: 1

-- Rotates the part by 90 degrees. If you want to change the axis your
-- rotating it on Use a different placement such as CFrame.Angles(math.rad(90),0,0)
Workspace.Part.CFrame = Workspace.Part.CFrame * CFrame.Angles(0, math.rad(90), 0)

Upvotes: 0

pighead10
pighead10

Reputation: 4305

I had this trouble too when I was starting to CFrame. They are RADIANS, not DEGREES. I have written a quick CFraming guide on ROBLOX, here.

If you're struggling with radians, you should look at the ROBLOX wiki page on radians to gain a basic understanding: wiki.roblox.com/index.php/Radians

Thanks!

-pighead10

Upvotes: 0

Eric
Eric

Reputation: 97571

The arguments taken specify position, not rotation

Upvotes: 1

Steffan Donal
Steffan Donal

Reputation: 2334

First, use the CFrame.fromEulerAnglesXYZ function to create a new CFrame pointing in the direction you wish. Then, use Vector3 math to move the CFrame into the desired position. EG.

local cframe = CFrame.fromEulerAnglesXYZ(XRADIANS, YRADIANS, ZRADIANS)
cframe = (cframe - cframe.p) + Vector3.new(XPOS,YPOS,ZPOS)

Upvotes: 2

Judge Maygarden
Judge Maygarden

Reputation: 27583

The documentation states that a Coordinate Frame (CFrame) constructor that takes 3 parameters is defining a position offset. Therefore, your example code would move the part 90 along the x-axis and 45 along the z-axis. To perform a rotation as you attempted see the CFrame.fromEulerAnglesXYZ function.

Upvotes: 1

Related Questions