PcoWSkbVqDnWTu_dm2ix
We use cookies on this site to enhance your user experience

Rotate a Part Using Degrees

Rotate a Part Using Degrees

Jun 23 2018, 8:09 AM PST

Problem

You want to rotate a part in degrees.

Solution

Use the DataType/CFrame|CFrame.Angles function and multiply it by the CFrame position using the math.rad function to convert degrees to radians.

local part = Instance.new('Part')
part.Parent = Workspace
part.Anchored = true
part.CFrame = part.CFrame * CFrame.Angles(0, math.rad(5), 0)

Discussion

We set part.CFrame to the same position part.CFrame and multiply it by CFrame.Angles but with math.rad(5) as the Y-axis rotation. The math.rad function converts degrees to radians. So in this case we are converting 5 degrees to radians and passing it to CFrame.Angles.

Other times you may see DataType/CFrame|CFrame.fromEulerAnglesXYZ. The function we’ve been using CFrame.Angles is just a shortcut function for CFrame.fromEulerAnglesXYZ. You shouldn’t use the old name (it’s much too long), but if you see it in code you will no longer be confused.

Tags:
  • math
  • coding