How do i use CFrame.fromOrientation()

could anyone give me an example how to use CFrame.fromOrientation()?
like, how do i rotate a part using that

2 Likes

The CFrame.fromOrientation() function has 3 parameters which are YXZ, you can apply orientation values to the parameters but you need to convert it to radians


local Part = game.Workspace.Part

for i = 1, 10

Part.CFrame = CFrame.new(Part.Position) * CFrame.fromOrientation(0, math.rad(45 + i), 0)

wait(1)

end

In this code, I made the part rotate every second.

2 Likes

what is YXZ? like, if i have XYZ, do i have to swap Y with X?

Yeah, because the Y axis rotates on the X axis and the X axis rotate on the Y axis, if you get what I mean.

so if i want to add 5, 10, 15 to parts orientation i would do

part.CFrame = part.CFrame * CFrame.fromOrientation(math.rad(10),math.rad(5),math.rad(15))

Yeah, that is going to make your part rotate on all axis. (just like when you throw a cube in the air, it rotates all over by itself)

okay, hopefully that helps me to fix my problem, thanks