I have a copy of a model in workspace inside a ViewportFrame. I am trying to set the camera for the ViewportFrame, but nothing shows up when I use the camera algorithm I want. I tested the algorithm by setting the CFrame of workspace’s CurrentCamera, so I know it should work. When I try to put the algorithm into production, not a single thing is shown in the ViewportFrame.
However: if I copy the generated camera object from the ViewportFrame into workspace, set the workspace.CurrentCamera to that camera, then copy the camera from workspace into the ViewportFrame and set the ViewportFrame’s camera to the copied camera, it shows the model as expected.
What’s different? The CFrame is different after setting Workspace.CurrentCamera.
Here’s what I’ve found:
-- good cframe 114.649765, 26.322279, -180.649765, -0.707106829, -0.610804081, 0.356256217, -0, 0.503822386, 0.86380738, -0.707106829, 0.610804081, -0.356256217 -- bad cframe 114.649765, 26.322279, -180.649765, -0.707106829, -0.462909967, 0.534522593, -0, 0.755929172, 0.65465349, -0.707106829, 0.462909967, -0.53452259
I’ve tested the bad CFrame for orthagonality by dotting
lookVector with each other, and they all have a dot product of 0 with the others. I attempted to create a new CFrame with the vectors of this using
CFrame.FromMatrix(cf.p, cf.rightVector, cf.upVector, -cf.lookVector)
and the CFrame generated from this is identical to the bad CFrame.
I’ve also attempted to create a matrix from scratch via several Cross products. - I have an input vector for camera direction and the up vector and everything sorts itself out from there (I also tried FromMatrix):
local CameraBackVector = (DirectionFromCenter + Vector3.new(0,math.sin(Theta),0)).unit local CameraRightVector = Vector3.new(0,1,0):Cross(CameraBackVector).unit local CameraUpVector = CameraBackVector:Cross(CameraRightVector).unit Camera.CFrame = CFrame.new(CameraCenter.X, CameraCenter.Y, CameraCenter.Z, CameraRightVector.X, CameraUpVector.X, CameraBackVector.X, CameraRightVector.Y, CameraUpVector.Y, CameraBackVector.Y, CameraRightVector.Z, CameraUpVector.Z, CameraBackVector.Z)
and still no dice. All these different methods work fine once Workspace.CurrentCamera have touched the camera, but I can’t generate a working CFrame for the life of me. I was quite handy with CFrame, so this is rather frustrating.
Can someone give me a hand at what I’m doing wrong?