Camera Math Help

I am currently writing a third person camera. This is what it looks like now: https://gyazo.com/c631c83fae14937b3ae9f60b67eadb0d

I want to add smooth camera motion. The formula being:

local Alpha = 0.1
Position += (Target - Position) * Alpha 

However, when I do this, I get this: https://gyazo.com/bb05120e684291eea3df50a20bc47356

Here is the code in RenderStepped:

local TargetPosition = Camera.CFrame.Position + (HumanoidRootPart.Position - Camera.CFrame.Position) * 0.1
			
local StartCFrame = CFrame.new(TargetPosition) * CFrame.Angles(0, math.rad(AngleX), 0) * CFrame.Angles(math.rad(AngleY), 0, 0)
			
local CameraCFrame = StartCFrame + StartCFrame:VectorToWorldSpace(OFFSET)
local CameraFocus = StartCFrame + StartCFrame:VectorToWorldSpace(Vector3.new(OFFSET.X, OFFSET.Y, 0))
			
Camera.CFrame = CFrame.new(CameraCFrame.Position, CameraFocus.Position)

I am not the best with CFrame math. Any help is appreciated!

2 Likes

I don’t know how much it’d help, but I’ve come to learn that overlapping tweens just long enough for one to switch on before the other switches off, makes for a more smooth effect.

local tweenService = game:GetService("TweenService")
local tweenInfo = TweenInfo.new(.2)
local tween = nil;

local function tweenCFrame(Object, Target)
    local t = tweenService:Create(Object, tweenInfo, {CFrame = Target})
    t:Play()
    if tween then tween:Stop() end
    tween = t
end

and then replace

with

tweenCFrame(Camera, CFrame.new(CameraCFrame.Position, CameraFocus.Position))

Also note that this was all wrote here in the reply box so I might have made some typo issues.