Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to Rotate a CFrame in a script?

The Title says it all. I know that for determining positions within a line of code I can do like Part.CFrame = Part.CFrame*CFrame.new(0,0,-100) that would move the part 100 studs forward to the direction its facing.

What I want to achieve is simple, I want to know how can I do the same with Rotations. Like how to rotate the CFrame to 180* in relation to the direction its facing. Any help is appreciated. Thanks in advance!!

1 answer

✓ Accepted answer

You would use this code to rotate the part in relation to its concurrent directiom:

Part.CFrame = Part.CFrame * CFrame.Angles(math.rad(180), 0, 0)

-- This will rotate the part 180 degrees on the X-Axis (relative to its direction before).
-- You can change the number inside "math.rad" to any number to change the degrees the part turns.

Like CFrame.new, CFrame.Angles has three values, the x (first), y (second), and z (third) value.

In the code example shown above, the part is being rotated on the x-axis. To change the axis the part is being rotated on, put the "math.rad(180)" in the second (y) or third value (z). This is pretty much the same as CFrame.new.

https://developer.roblox.com/en-us/api-reference/datatype/CFrame - A good reference for this topic.

2 comments

0

Thank you brother

0

Np

This discussion is preserved as it was. New answers, comments, and votes are closed.