Issue with Aim Down Sights in First-Person View
Introduction
I’m trying to implement the Aim Down Sights (ADS) effect in a first-person shooter game on Roblox. However, when aiming, the effect doesn’t work as expected.
Here is an example of how it should work:
And here is how it currently works for me:
Current Code
Currently, I’m using the following code to handle the aiming animation:
RunService.RenderStepped:Connect(function()
if Player.Character and Player.Character.Humanoid.Health == 0 then
if Camera:FindFirstChild("ViewModel") then
Camera.ViewModel:Destroy()
end
end
if Camera:FindFirstChild("ViewModel") then
local mouseDelta = UserInputService:GetMouseDelta()
local sway = calculateSway(mouseDelta)
local walkSway = calculateWalkSway()
local aim = calculateAim()
-- Apply camera movement (sway + walk sway + recoil)
swayCF = swayCF:Lerp(sway * walkSway, SWAY_SMOOTHNESS)
-- Apply aiming
if isAim then
aimCF = aimCF:Lerp(aim, AIM_SMOOTHNESS_ENTER)
else
aimCF = aimCF:Lerp(CFrame.new(), AIM_SMOOTHNESS_LEAVE)
end
-- Move the camera
ViewModel.CameraBone.CFrame = (Camera.CFrame * CFrame.new(0, -1, 0)) * swayCF * aimCF
end
end)
ADS Calculation
-- Function to calculate aiming
local function calculateAim()
if isAim and CharacterModule.CURRENT_WEAPON then
local WEAPON_MODEL = ViewModel:FindFirstChild(CharacterModule.CURRENT_WEAPON.NAME)
if WEAPON_MODEL then
local aimPart = WEAPON_MODEL.PrimaryPart.Aim
if aimPart then
local offset = aimPart.CFrame:ToObjectSpace(ViewModel.PrimaryPart.CFrame)
return offset
end
end
end
return CFrame.new()
end
Weapon Model Structure
My weapon model has the following structure:
Current Issue
The problem is that when I try to aim, the view does not align correctly with the weapon’s “Aim” part. In the first video, the ADS effect works smoothly, while in my implementation, there is a misalignment in the camera position.
Question
- Can someone help me fix my ADS implementation?
- What is the correct way to align the view with the AimPart?
- Should I modify my interpolation method (Lerp), or is there another error in the offset calculation?
I would appreciate any help or suggestions to achieve the correct effect.