Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How can I get a certain component of a CFrame?

Asked by
Tesouro 407 Moderation Voter
9 years ago

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?

0
Why do you want the rotation values? BlueTaslem 18071 — 9y

1 answer

Log in to vote
0
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
9 years ago

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?

0
Hum.. yeah, I thought of that, it is a bit difficult. Well, I'm making some CFrame experiments, and I wanted the value of it to set camera settings. Anyhow, thx. Tesouro 407 — 9y
Ad

Answer this question