Hello, i want to implement an ADS (Aim Down Sights) system in my FPS Game.
local TweenService = game:GetService("TweenService")
local userInput = game:GetService("UserInputService")
local AimPart = viewModel:WaitForChild("AimPart")
local isAiming = false
local originalCameraCFrame = camera.CFrame
local function tweenCamera(targetCFrame, duration)
local tween = TweenService:Create(
camera,
TweenInfo.new(duration, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut),
{CFrame = targetCFrame}
)
tween:Play()
end
userInput.InputBegan:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseButton2 then
isAiming = true
originalCameraCFrame = camera.CFrame
-- Tween the camera to the AimPart's CFrame
tweenCamera(AimPart.CFrame, 10)
end
end)
userInput.InputEnded:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseButton2 then
isAiming = false
-- Tween the camera back to its original view
tweenCamera(originalCameraCFrame, 0.3)
end
end)
The problem is, when i hold down the right mouse button, a camera glitch occurs which prevents me from moving. And i am using tool based viewmodels by the way. In the context of the script, the targetCFrame is the AimPart’s CFrame, located behind the iron sight of the gun Model (which is located in the viewModel)
I’ve tried offsetting, creating new cameras, using FPS Guides on Forums but unfortunately nothing works. I even resorted to trying AI but that also didn’t fix my problem.
and for reference, the image is how i want my ads to look like.