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

How to Rotate a CFrame in a script?

Asked by 2 years ago
Edited 2 years ago

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

Log in to vote
2
Answered by 2 years ago
Edited 2 years ago

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.

0
Thank you brother Shounak123 461 — 2y
0
Np SprinkledFruit101 135 — 2y
Ad

Answer this question