I’ve recently discovered an addition to CFrame documentation under
CFrame.new(Vector3 pos, Vector3 lookAt) constructor:
This constructor has been deprecated in favor of using `CFrame.fromMatrix(), to create a lookVector
It seems really strange to have this constructor deprecated in favor of a constructor that takes matrix values to construct a CFrame, since it seems like performing the necessary math on Lua takes quite a bit more time:
local v1 = Vector3.new(1.1, 1.2, 1.3)
local v2 = Vector3.new(0.75, 5.8, 6)
function lookAt(target, eye)
local forwardVector = (target - eye).Unit
local upVector = Vector3.new(0, 1, 0)
-- You have to remember the right hand rule or google search to get this right
local rightVector = forwardVector:Cross(upVector)
local upVector2 = rightVector:Cross(forwardVector)
return CFrame.fromMatrix(eye, rightVector, upVector2)
end
local t1 = tick()
for i = 1, 1000000 do
local x = CFrame.new(v1, v2)
end
print(tick() - t1)
local t2 = tick()
for i = 1, 1000000 do
local x = lookAt(v2, v1)
end
print(tick() - t2)
Output:
0.12635779380798
0.49749302864075
Is this intentional? I’m pretty confused lol
Link to CFrame documentation: