Aim down sights not working

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:

Screenshot 2025-01-30 152625

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.

heres how I’d manage a aim mechanic

  • instead of using a cframe value that stores the aim offset, I’d use a numerical value that stores how aimed in the player is (so i can tween it from 0 - 1 for a smooth aim transition)
  • then, using the aim value, id lerp the viewmodel’s current position to a position where the aimpart is positioned at the camera
local offset = (ViewModel.CameraBone.CFrame:Inverse() * aimPart.CFrame):Inverse() --get the amount the position of the viewmodel has to be offset to position the aimpart on the camera
	ViewModel.CameraBone.CFrame *= CFrame.new():Lerp(offset, ADSVALUE) --do this line AFTER you move the viewmodel in this line "ViewModel.CameraBone.CFrame = (Camera.CFrame * CFrame.new(0, -1, 0)) * swayCF"