Given an arbitary Vector3, how do I convert it to Orientation?
I didn’t understand your question properly. Would you mind explaining it?
The .Orientation property of baseparts are already Vector3s and takes degrees as an argument.
You can also create a new CFrame by providing the position and matrix of the CFrame by using CFrame.fromMatrix.
If you mean applying an offset to an existing basepart’s CFrame, you can take the original BasePart’s CFrame and multiply it by the offset using CFrame.Angles (which takes radians as its arguments)
local part = workspace.Part part.CFrame *= CFrame.Angles(0,math.rad(90),0)
Could you give an example of what you want?
I think their question is, given 2 points in space, A,B, vector origin, vector value.
What is the angle from A to B, in orientation form.
Explicitly, I mean like, where Vector3.new(1,1,0) is a unit vector that could be a parts LookVector, what would that parts Orientation be (the answer is Vector3.new(45,0,0) in degrees). I want to do that mathematically though, converting from LookVector to Orientation basically.
There is a part’s property called orientation
Creating an Instance just to read its Orientation after setting its CFrame off the LookVector of the Vector is a wasteful and improper solution. I am asking for the mathematical solution rather.
Orientation is noncommunative I think in the order applied X,Y,Z so perhaps backstepping that on each relative dimension of the Vector3 as its converted and using the dot product to get the angle might have something to do with it.
You can’t (assuming we’re talking about a directional vector). For instance, if you had a unit look vector of (0, 1, 0) facing straight up, could you say what its orientation is? Well, you could say that the X and Z orientation is 0, but the Y orientation could be anything. As long as you just rotated it on the Y axis, the look vector would remain the same.
In order to derive orientation from a vector, we need another vector to describe a secondary direction (usually an up vector). This is why
CFrame.lookAt has a third
up vector parameter (defaults to straight up).
If we go down the
lookAt route, we can use the CFrame APIs to do all of this without having to mess with any math on our end. All we need to do is construct a CFrame using
lookAt, and then transform it to orientation using the
local someLookVector = Vector3.new(...blah) local upVector = Vector3.new(0, 1, 0) local cf = CFrame.lookAt(Vector3.new(), someLookVector, upVector) local x, y, z = cf:ToOrientation()
Please note: The
x, y, z variables are in radians, not degrees. This is really confusing because Roblox shows Orientation on BaseParts in degrees instead.