How would i make my gun aim smoother

Yes i have read other topics.

My aiming works fine, but i want it smoother.
I tried looking up answers but no success. I tried lerping and tweenservice, all with 0 success.

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

this is how my lerping looked.

Also tried: camera.CFrame = usedVM.Gun.Aim.CFrame
That works but it just snaps, and i want a smooth transition

how it looks: https://gyazo.com/f3f387981ce2cdcf8be8417a4a1f4506

How do i make it smoother?

2 Likes

you just extend the time it takes to make it ADS, preferrably with tween service, but whatever floats your boat

also, i really hate how that part of your gun is longer on the left

1 Like

Oh yeah, that left arm is long as fck. I will try one more time with tweenservice.

Thanks

1 Like

you absolute silly buffon

not arm, i mean this:
image

I never in my life noticed that, because of you i cant unsee it :man_facepalming:

But i tried tweenservice:

local tween = Tweenservice:Create(camera, info, {CFrame = usedVM.Gun.Aim.CFrame})
tween:Play()

Spoiler alert: Camera glitches out.

Refer to the video: https://gyazo.com/e0daf3c6b4a657b145fa651753d9346a

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.