How would i make my gun aim smoother

Hello,

You are on track as you can definitely use the :Lerp() function. I recommend binding it to RunService with the BindToRenderStepped event. This will ensure that the function runs every frame, which can help maintain consistency.

If you’re already using BindToRenderStepped, the solution can be simple, such as:

local targetVCFF = usedVM.Gun.Aim.CFrame
local smoothFactor = 0.1 -- Adjust this for smoother or snappier aiming

camera.CFrame = camera.CFrame:Lerp(targetVCFF, smoothFactor)

In the context of the :Lerp() function, the value you use for the alpha parameter affects the ‘smoothness’ of the transition, which is what the smoothFactor is.

Funny enough is that it wont work.
Welll, i mean it does something.

https://gyazo.com/9b7c5fc4ff56343e2470d3553422937c

I might drink a espresso because im a little depresso

That’s odd. Could you share a bit more of your code? I’m not entirely clear on what you’ve tried so far, and seeing more of your implementation would really help figure out the issue.

local buttons = uis:GetMouseButtonsPressed()
			local m2 = false
			for _, key in buttons do
				if key.UserInputType.Name == "MouseButton2" then
					m2 = true
				else
					m2 = false
				end
			end

			if m2 then
				--camera.CFrame = usedVM.Gun.Aim.CFrame
				
			end
``

i use rs.RenderStepped:Connect(function(dt because i feel like it. Idk if it matters using :bindtorenderstep

Combinung lerp and Tweenservice getvalue should work

The only difference is that using :BindToRenderStepped() allows you to UnbindFromRenderStepped, if that is required later on, but .RenderStepped works as well.

Ive seen that exact post and couldent really get how i would implement that in my system. If you could explain, that would be really good.

See if this helps, it uses the same method that you originally had (as it seemed like it was working for you) but with perhaps that smoother transition that you wanted. I hope you can implement it as I’m not completely sure how your script is set up.

local buttons = uis:GetMouseButtonsPressed()
local m2 = false
local smoothness = 100

for _, key in buttons do
	if key.UserInputType.Name == "MouseButton2" then
		m2 = true
	else
		m2 = false
	end
end

if m2 then
	if not inAim then
		inAim = true

		local targetVCFF = usedVM.Gun.Aim.CFrame
		for i = 0, smoothness do
			camera.CFrame = camera.CFrame:Lerp(targetVCFF, i / smoothness)
			task.wait()
		end
	end
end

If there’s any questions let me know

i will forever hate camera scripting

it’s a reason i call myself the worst camera scripter, it’s literally impossible

oh well, i tried

It doesnt work, and what doesnt work is that it wont aim now.

https://gyazo.com/f74c0af070ca8858b42f6aa20926aba2

Hmm alright, I suggest you backtrack a bit to the last working version of your code, and then from there, try making this small adjustment:

local targetVCFF = usedVM.Gun.Aim.CFrame
if not inAim then
    inAim = true
    for i = 0, 100 do
        camera.CFrame = camera.CFrame:Lerp(targetVCFF, i / 100)
        task.wait()
    end
end

Does this change make a difference?

I tried it out and nothing has changed, i might aswell give the whole script

Script ahh:

rs:BindToRenderStep("VIewmodel", Enum.RenderPriority.Camera.Value + 1, function()
	if not tool then return end

	if char:FindFirstChildWhichIsA("Humanoid").Health <= 0 then
		if camera:FindFirstChild(tool.Name) ~= nil then
			workspace.Camera:FindFirstChild(tool.Name):Destroy()
		end
	end

	if equipped then
		if camera:FindFirstChild(tool.Name) ~= nil then
			usedVM = camera:FindFirstChild(tool.Name)
			local delta = uis:GetMouseDelta()

			local x = clamp(delta.X, -.2, .2)
			local y = clamp(delta.Y, -.2, .2)

			swayCF = swayCF:Lerp(cfNew(x, y, 0), .02)

			usedVM:PivotTo(
				camera.CFrame * swayCF
			)

			local buttons = uis:GetMouseButtonsPressed()
			local m2 = false
			for _, key in buttons do
				if key.UserInputType.Name == "MouseButton2" then
					m2 = true
				else
					m2 = false
				end
			end

			if m2 then
				--camera.CFrame = usedVM.Gun.Aim.CFrame

			end
		end
	end
end)

It would be very helpful. If you’re comfortable sharing the whole script, it might be easier for me to see the issue.

Sorry if my math is kinda crack.
I don’t know where to search to learn it, and school doesn’t learn me either.

if not inAim then
  inAim = true
  local tween = Tweenservice:Create(camera, info, {CFrame = usedVM.Gun.Aim.CFrame})
  tween:Play()
end

This kinda works, but for like .1 second and it just snaps back.
https://gyazo.com/b48b6eb9fd63cc033f533253baf6a10d

Try this, I’ve changed the way you handled the m2 variable and a few other things that could be relevant to the issue:

local m2 = false

rs:BindToRenderStep("Viewmodel", Enum.RenderPriority.Camera.Value + 1, function()
	if not tool then
		return
	end

	if char:FindFirstChildWhichIsA("Humanoid").Health <= 0 then
		if camera:FindFirstChild(tool.Name) ~= nil then
			workspace.Camera:FindFirstChild(tool.Name):Destroy()
		end
	end

	if equipped then
		if camera:FindFirstChild(tool.Name) ~= nil then
			local usedVM = camera:FindFirstChild(tool.Name)
			local delta = uis:GetMouseDelta()
			local x = clamp(delta.X, -.2, .2)
			local y = clamp(delta.Y, -.2, .2)
			local m2 = false
			local targetCf = usedVM.Gun.Aim.CFrame
			
			swayCF = swayCF:Lerp(cfNew(x, y, 0), .02)
			usedVM:PivotTo(camera.CFrame * swayCF)

			if aiming then
				--camera.CFrame = usedVM.Gun.Aim.CFrame
				camera.CFrame = camera.CFrame:Lerp(targetCf, 0.05)
			end
		end
	end
end)

uis.InputBegan:Connect(function(input, gc)
	if not gc then
		if input.UserInputType == Enum.UserInputType.MouseButton2 then
			m2 = true
		end
	end
end)

uis.InputEnded:Connect(function(input, gc)
	if not gc then
		if input.UserInputType == Enum.UserInputType.MouseButton2 then
			m2 = false
		end
	end
end)

Same thing still happens.
https://gyazo.com/202ff42ee71ddf903241ac9075c47c1f

That’s strange, when I tested it on studio it worked fine. You said that Tweening worked to some extent for you before I had sent the message, what was info?
https://gyazo.com/10e62fac9a3fb1a043622364e2e7212d.mp4

HI,
Info is: local Info = TweenInfo.new( .3, Enum.EasingStyle.Cubic )