So I have my custom OTS Camera and I’m trying to make a target lock on system which works really well except one problem. When Unlock from the target the camera returns to the previous position of where the player was looking at and can be quite disruptive and non smooth during gameplay. Here is an example of what I mean:
https://gyazo.com/023f7757273e1156fc7cfa52f3526b08
Here is the block of code for updating the camera:
--[[ Update Camera ]]--
local StartCFrame = CFrame.new((HumanoidRootPart.CFrame.p + Vector3.new(0, 2, 0))) * CFrame.Angles(0, math.rad(xAngle), 0) * CFrame.Angles(math.rad(yAngle), 0, 0)
local Offset = Camera.CameraSettings.Offset
local CameraCFrame = StartCFrame + StartCFrame:VectorToWorldSpace(Vector3.new(Offset.X, Offset.Y, Offset.Z))
local CameraFocus = StartCFrame + StartCFrame:VectorToWorldSpace(Vector3.new(Offset.X, Offset.Y, -50000))
local NewCameraCFrame = CFrame.new(CameraCFrame.p, CameraFocus.p) * (ShakeCFrame.Value)
if (CombatProperties.Target.Value ~= nil) then
Offset = Vector3.new(Offset.X + 2, 2, Offset.Z)
CameraCFrame = CFrame.new(Character.HumanoidRootPart.Position, CombatProperties.Target.Value.PrimaryPart.Position) * Offset
NewCameraCFrame = CurrentCamera.CFrame:Lerp(CFrame.new(CameraCFrame, CombatProperties.Target.Value.PrimaryPart.Position) * (ShakeCFrame.Value), 0.5)
end
When the player unlocks from the target I want the camera to stay where it is positioned but the player can just freely move their camera again.