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

How to properly use CFrames?

Reposting because I got no answers last time. I have renamed it to more accurately represent the issue.

I'm probably messing up the CFrame on line 17, embarrassingly I have no idea how to use them, the dev-api didn't help much. In this scenario I want to generate a Lorenz system vector field, though when I run it I get insane values in the orientation (Ex. -21474836) and it causes the parts to just, kind of, not render.

local sigma = 10
local rho = 28
local beta = 8/3

function GenerateVectorField(style, scaleX, scaleY, scaleZ)
	local VectorField = {}
	if style == 0 then
		for i=1, scaleX do
			for j=1, scaleY do
				for k=1, scaleZ do
					local Location = Vector3.new((scaleX/2)*(-1)+i, (scaleY/2)*(-1)+j, (scaleZ/2)*(-1)+k)
					
					local x = Location.X
					local y = Location.Y
					local z = Location.Z
					
					local Vector = CFrame.fromMatrix(Location, Vector3.new(0, 0, 0), Vector3.new(sigma * (y - x), rho * x - y - x * z, x * y - beta * z), Vector3.new(0, 0, 0))
					table.insert(VectorField, i, Vector)
				end
			end
		end
	end
	return(VectorField)
end


local VectorField = GenerateVectorField(0, 10, 10, 10)
local Output = Instance.new("Folder", workspace)
for i=1,#VectorField do
	local part = Instance.new("Part", workspace.Folder)
	part.Size = Vector3.new(0,0,0)
	part.CFrame = VectorField[i]
	part.Anchored = true
	part.Transparency = 1
	local Cone = script.ConeHandleAdornment:Clone()
	Cone.Parent = part
	Cone.Adornee = part
end

How do I use CFrame properly in this scenario? When just setting position with CFrame.new everything works, so the rest of the script is all good.

1 answer

✓ Accepted answer

When using the CFrame.fromMatrix constructor, the three rotational vectors have to be unit vectors, vectors of length of one. You are setting the rightVector and lookVector to 0 vectors, which is against the rules of CFrames. rightVector has to be Vector3.new(1,0,0), and the lookVector has to be Vector3.new(0,0,1).

local Vector = CFrame.fromMatrix(Location, Vector3.new(1, 0, 0), Vector3.new(sigma * (y - x), rho * x - y - x * z, x * y - beta * z), Vector3.new(0, 0, 1))

2 comments

0

that fixed the problem, but the orientation is only being half set, so y is always 0. How do I fix this? I want to set the x, y, z of the orientation to sigma * (y - x), rho * x - y - x * z, x * y - beta * z

0

Instead you simply construct a rotational cframe using CFrame.Angles(x,y,z)

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