Converting CFrame.lookVector to radian angle values

Hi,

When I use lookVector I get numbers like:

[0.53380155563354,0.086807556450367,-0.84114223718643]
[0.55477094650269,0.086807563900948,-0.8274621963501]

What I am trying to get is that number but in radians. How can I get this? What I am making is a directional looking system using camera location. If there is a better way to approach this let me know also!

I need lookVector numbers because I need to know where the camera is facing so I can sure a players head respectively.

3 Likes

math.rad?

With these numbers, I don’t he is looking for radians. I’m a bit confused.

You can multiply the number by 180, then divide by pi to get the degrees. Im not sure why you need the radians of these numbers.

x = x*180/(22/7)

The question doesn’t really make sense since a CFrame’s LookVector is its forward-direction component. It’s a unit vector describing the direction it’s facing towards. What you probably want to do is create a Camera CFrame pointing at/away from another CFrame (like an object or point in space)?

1 Like

You can extract the orientation information from a CFrame in a few different formats. Those numbers you have for the LookVector are the x, y and z components (in World coordinates space) of a unit vector that represents the negative Z-axis of the CFrame (by Roblox convention, -Z is always the Look direction, whereas +Y and +X are the Up and Right, respectively).

If you want angles, there are a bunch of different helper functions that get you values in Radians. My personal favorite is radX, radY, radZ = CFrame:ToOrientation() which returns an Euler angles tuple (Tait-Bryan YXZ order specifically) ,which gives you the rotation around the X axis, Y axis and Z axis in radians. One thing that’s important to note is that the tuple is always in X, Y, Z order even if the name of the function has YXZ. The ordering in the name of the function is the order the rotations are decomposed, it has nothing to do with the order of the return values. YXZ order is the traditional Yaw, Pitch, and Roll, or Heading, Elevation, Bank. In spherical coordinates, yaw/heading is also called azimuth.

The other function that gives you a radians value is CFrame:ToAxisAngle(). This function gives you the orientation of the CFrame in the form of a world-space vector that is the axis of rotation, and a scalar value for angle which is how many radians around that axis the frame is rotated.

26 Likes

Thank you.

1 Like