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.
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
``
The only difference is that using :BindToRenderStepped() allows you to UnbindFromRenderStepped, if that is required later on, but .RenderStepped works as well.
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
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
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)
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)