Like the title says, I’m asking for a new CFrame constructor.
CFrame.new(Vector3 p, Vector3 right, Vector3 up[, Vector3 back])
This would create a rotated CFrame from a position and the first two column vectors of the rotation matrix. The third column vector would be optional–if omitted, it would be inferred from the first two by normalizing their cross product.
###Why we need it
Here’s some code I wrote a few minutes ago to answer a question in development discussion. It uses the common pattern of taking some column vectors, crossing a bunch of things, and then packing the individual components into the CFrame matrix.
Take note of the last line–specifically, how it indexes 12 userdata fields, and how the syntax looks like roadkill.
local p2c = p2.CFrame
local vz = -p2c.lookVector
local vy = p1.CFrame.rightVector:Cross(vz).unit
local vx = vy:Cross(vz).unit
p2.CFrame = CFrame.new(p2c.x, p2c.y, p2c.z, vx.x, vy.x, vz.x, vx.y, vy.y, vz.y, vx.z, vy.z, vz.z)
That’s pretty garbage. Let’s refactor with the constructor I’m proposing.
local p1c = p1.CFrame
local p2c = p2.CFrame
p2.CFrame = CFrame.new(
p2c.p,
p1c.rightVector,
p2c.lookVector:Cross(p1c.rightVector).unit
)
The second way saves time and mitigates a potential source of bugs.