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
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)