Hey all, i am programming an over the shoulder and first person system but have recently ran into an issue. The way the script works is it updates (every frame that the player is in third person) the cameras CFrame, taking the current orientation and multiplying it by the mouse delta.
However theres an issue, as seen in this gif sometimes when zooming out from first person the mouse will randomly move to a different position, there seems to be no reproduction for this, it happens on all parts about 40% of the time, so i can only its a problem with the math/ its not meshing well with robloxs scroll scripts.
local function UpdateOTS()
local Character = Player.Character
local rootPart = Character:FindFirstChild("HumanoidRootPart")
if Character and rootPart then
local Delta = UserInputService:GetMouseDelta()
xAngle = xAngle-Delta.x*0.4
yAngle = math.clamp(yAngle-Delta.y*0.4,-80,80)
UserInputService.MouseBehavior = Enum.MouseBehavior.LockCenter
local startCFrame = CFrame.new((rootPart.CFrame.Position + Vector3.new(0,2,0)))*CFrame.Angles(0, math.rad(xAngle), 0)*CFrame.Angles(math.rad(yAngle), 0, 0)
--Set camera focus and cframe
local cameraCFrame = startCFrame + startCFrame:vectorToWorldSpace(Vector3.new(otsOffset.X,otsOffset.Y,otsOffset.Z))
local cameraFocus = startCFrame + startCFrame:vectorToWorldSpace(Vector3.new(otsOffset.X,otsOffset.Y,-50000))
local cf = Camera.CFrame:Lerp(CFrame.new(cameraCFrame.p,cameraFocus.p),0.75)
Camera.CFrame = cf
end
end
That is the code, any help is greatly appreciated 