How can I set the camera to move and adjust smoothly and efficiently?
I tried this solution among many others:
--[[LocalScript: Inside of StarterPlayerScripts]]--
local Camera = workspace.CurrentCamera
local mult = 1
lastCameraCF = Camera.CFrame
function RenderLoop()
local rotation = Camera.CFrame:toObjectSpace(lastCameraCF)
local x,y,z = rotation:ToOrientation()
swayOffset = swayOffset:Lerp(CFrame.Angles(math.sin(x)*mult,math.sin(y)*mult,0), 0.1)
lastCameraCF = Camera.CFrame --update the last cframe
end
NOTE: I replaced ‘swayOffset’ with ‘Camera.CFrame’ because…
However I don’t know what to set swayOffset
to…
The desired sway works, however, the camera re-center’s in one direction as shown below.
Also, my camera seems to be rooted at the spawn, this only occurs with the above code…
I’d appreciate a fix to this, or a reliable alternative.
Edits
-
Removed blurred comment from post. Going to sleep now, will be back in the morning looking for answers!
-
Added the script type and location above example. –[[LocalScript: Inside of StarterPlayerScripts
]]– -
Added variable
Camera
to example code. local Camera = workspace.CurrentCamera
I understand this is unnecessary, I just wanted to do it