Still have questions? Join our Discord server and get real time help.

Log in to vote

0
After having learned how to put one position with another rotation, I now need to figure out how to get one rotation value (rY). I'm trying to rotate my character depending on the direction of the camera, except I only want the character to be able to spin along the y axis, not the x or z, or else he won't be standing up straight. So, how would I simply get the rotation value of the camera on the Y axis while leaving the Z and X at 0?

Log in to vote

1
The rotational part of `CFrames`

can be converted to *Euler angles*. This is basically three numbers representing the rotation of each of the three axes. We can get the Euler angles of a `CFrame`

called `cf`

by doing `local x , y , z = cf:ToEulerAngles()`

. We can then construct a rotational `CFrame`

again using `CFrame.Angles(0 , y , 0)`

. The zeroes in the `x`

and `z`

fields mean that the `x`

and `z`

angles of the character won't be changed.

local camera = workspace.CurrentCamera local x , y , z = camera.CFrame:ToEulerAngles() local rotation = CFrame.Angles(0 , y , 0) local position = CFrame.new(humanoidRootPart.Position) local result = position * rotation character:SetPrimaryPartCFrame(result)

0

Thanks again! I've learned so much from you today lol cowsoncows 779 — 2y

1

For the record. As of 2019 the method is now `:ToEulerAnglesXYZ()` joeldes 201 — 1y