Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How can I get a certain component of a CFrame?

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?

1 comment

0

Why do you want the rotation values?

1 answer

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?

1 comment

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.