How do i make a part look at another part with CFrame.Matrix()?

How do i use CFrame.Matrix() to make a part look at another part?

I don’t know about CFrame.Matrix specifically since it’s a little more complicated, but you can always use
part.CFrame = CFrame.new(part.Position, partToLookAt.Position)

1 Like

Yes I know how to use that method but it’s deprecated.

Really curious as to how you’d use matrix multiplication to achieve this with CFrames, I think it’d be very insightful as to how they work. If anyone knows please do answer.

Other than a couple of flaws, it doesn’t look deprecated. Am I missing something?

If nobody beats me to it, I’ll go get it for you.

Actually it’s right there on the page for CFrame.

function lookAt(target, eye)
    local forwardVector = (target - eye).Unit
    local upVector = Vector3.new(0, 1, 0)
    -- Remember the right-hand rule
    local rightVector = forwardVector:Cross(upVector)
    local upVector2 = rightVector:Cross(forwardVector)
 
    return CFrame.fromMatrix(eye, rightVector, upVector2)
end
2 Likes

Ahh, that’s not what I meant. I know it’s unnecessary, but I was wondering if there was a way that you could multiply the matrices of the part and the partToLookAt to get the matrix that you found.