Get Orientation from Directional Vector

The title explains it all
How to Get Orientation from Directional Vector
So like you have Vector3.new(0,1,0) and that translates to (90,0,0)

1 Like

I believe that this is the way to do it:

local v = Vector3.new(0, 1, 0)

local function vectorToOrientation(vector)
    return CFrame.new(vector):ToOrientation()
end

print(vectorToOrientation(v))

You can read more about it here: CFrame | Roblox Creator Documentation.

For this to happen I believe you mean that this vector is rotating from Vector3.new(0,0,-1) look vector to up vector, so it’s rotating along it’s RightVector or x axis by 90 degrees.

You can then use this advanced CFrame trick to make what you said work:

local function getRotationBetween(u, v, axis)
local axis = axis or Vector3.new(0,1,0) --backup axis
    local dot, uxv = u:Dot(v), u:Cross(v)
    if (dot < -0.99999) then return CFrame.fromAxisAngle(axis, math.pi) end
    return CFrame.new(0, 0, 0, uxv.x, uxv.y, uxv.z, 1 + dot)
end

local function toDegrees(...)
	local degs = {...}
	for i ,rad in pairs(degs) do
		degs[i] = math.deg(rad)
	end
	return table.unpack(degs)
end

local v1 = Vector3.new(0,0,-1)
local v2 = Vector3.new(0,1,0)
local result = getRotationBetween(v1,v2)
print(toDegrees(result:ToOrientation()))
--Result in output
  20:27:49.727  89.980215446453 0 0  -  Edit
close to (90,0,0) orientation only approximation
3 Likes