Get LookVector of CFrame as if it was applied to a part

Title.
But more specifically:
If i align a CFrames UpVector to a Normal, and try to get the LookVector, it acts as if it didn’t even rotate. (or i’m missing something)

function UpVectorToNormal(CF, Normal)
	return CFrame.fromMatrix(Vector3.new(0,0,0), CF.lookVector:Cross(Normal), Normal, -CF.lookVector)
end

Here is the code.
If you apply the returned CFrame to a part and then get the LookVector, it works correctly.
But that’s a roundabout method.

Expected outcome (somewhat):
image

Current Outcome:
image

LookDemo.rbxl (29.2 KB)

It’s because of the -CF.lookVector in the UpVectorToNormal function. Simply leaving it out fixes the problem, what it should be and what it’s automatically calculated as is

Vector3.new(0, 0, 0):Cross(CF.lookVector:Cross(Normal)).Unit

Giving anything other than that can cause problems, such as certain values in the CFrame being zeroed because it can’t mathematically exist with the other values, or the normals being inverted.

(and also .lookVector is deprecated, use .LookVector)

And where exactly should i put this?

Change

return CFrame.fromMatrix(Vector3.new(0,0,0), CF.lookVector:Cross(Normal), Normal, -CF.lookVector)

to

return CFrame.fromMatrix(Vector3.new(0,0,0), CF.lookVector:Cross(Normal), Normal)
1 Like