CFrame.fromMatrix is giving extreme visual issues when applied to camera

I recently saw that CFrame.new(v1,v2) for creating a look at CFrame was deprecated, so I attempted to implement the suggested alternative which I don’t understand in the slightest.

How in the world do you get a rotation matrix from 3 cross products which are essentially the area of the vector’s cube trapezoid thing?

I decided to disregard attempting to understand it and used it on my camera for a neat little menu effect. But jokes on me because using it results in the camera FOV being completely broken or the screen just turns black. How do I fix this?

function lookAt(eye, target) -- This is the function straight from the wiki
    local forwardVector = (eye - target).Unit
    local upVector = Vector3.new(0, 1, 0)
    local rightVector = forwardVector:Cross(upVector)
    local upVector2 = rightVector:Cross(forwardVector)
 
    return CFrame.fromMatrix(eye, rightVector, upVector2)
end

workspace.CurrentCamera.CFrame = lookAt((CFrame.new(0,30,5) ).p,Vector3.new())

Results: Instead of looking at the part at 000, the screen looks like this…

If we change that 5 to a 0, this happens…

Notice how the deprecated solution works perfectly:

Awesome. Imagine deprecating something then having the new and suggested solution be way more complicated and work significantly worse.

Is this a bug or am I just uninformed? Thanks in advance.

4 Likes

This line should be changed to:

local forwardVector = (target - eye).Unit

Also, to specify, the Magnitude of the cross product of two vectors is the area of the parallelogram that the two vectors form, and the actual cross product of two vectors is a vector that is perpendicular to those two vectors

2 Likes

Thanks, but unfortunately your solution only solved the direction problem. We’ve still got that hyper speed effect

Weird. Are you sure you’re not changing the FOV? This is the first time i’ve seen something like this happen…

Yeah Its quite bizarre. I can assure you that the FOV is never being touched, and is a static value of 70.

Should I switch this to a bug report instead?

This appears to be a problem with the way you’re constructing the CFrame (But I’m not sure what the problem is if that makes sense).

This effect looks like something I’ve seen before and perhaps the information on this post may help you have some useful insight that solves or more clearly identifies the problem.

This effect seems to be created by mutating the camera’s rotation matrix.

Oh yeah this definitely looks like its probably the underlying cause. I’m not sure if this is the intended behavior that the engineers were expecting when this function was created and they decided to deprecate Cf.new(v1,v2).

What the wiki suggests, is an inadequate replacement.
If you don’t want to use CFrame.new(pos,lookAt), this should do a better job.

2 Likes