A CFrame is made of 12 numbers: x, y, z, R00, R01, R02, R10, R11, R12, R20, R21, R22
and I want to get the value of R01
, for example.
How can I do that directly (or not) from the CFrame?
Unfortunately I can't think of a better way to do this than coercing the CFrame to a string and then parsing it:
local str = tostring(someCFrame) .. ","; local matrix = {}; local acc = ""; for i = 1, #str do local c = str:sub(i, i); if c == "," then if #acc > 0 then table.insert(matrix, tonumber(acc)); acc = ""; end elseif c:gsub("%s", "") ~= "" then acc = acc .. c; end end
matrix
then should contain the 12 values in the order you pass them to the constructor, so, matrix[5]
should be R01
.
However, there shouldn't often be a reason to do this; why do you want the components of the matrix?