I’ve been attempting to create a camera system that will follow every aspect of a part, its position and rotation. My goal is to make it so that no matter where the part is in the world or how it is rotated, it will stay in the same position on the screen.
Here’s the code I’ve come up with:
function updateCamera()
local charVector = char.Position
local relativeCFrame = char.CFrame:ToWorldSpace(offsetCFrame) -- offsets the camera based on rotation of the character
workspace.CurrentCamera.CFrame = CFrame.lookAt(relativeCFrame.p, charVector)
workspace.CurrentCamera:SetRoll(char.Orientation.x*-1) -- applies a roll effect
end
This works for the most part except in some weird situations. For example, when the parts orientation is (90, 0, 0)
(which should turn the camera -90 degrees on the Z axis), I get this mess:
As you can see, for some reason the camera is turning just a bit too much towards the ground.
There are many other examples of weird stuff happening when I use this method, but I’m much more interested in learning why it is happening and all and how I can fix it.