I’ve been continuing progress on my first person shooter, but i’ve run into an unusual problem,
Whenever i play in high FPS (around 120fps or higher), the camera recoil goes insane when i shoot, and the viewmodel.
I’m not sure what to do in all honesty, i could play with deltatime but i’m not sure how to quite do that, and i’ve heard it doesn’t make a difference, so what could i possibly do?
Module Script:
function module.update(viewmodel, dt, RecoilSpring, BobbleSpring, SwaySpring)
for i,v in pairs(viewmodel:GetChildren()) do
if v:IsA("MeshPart") or v:IsA("Part") then
v.CanCollide = false
end
end
viewmodel:SetPrimaryPartCFrame(workspace.Camera.CFrame)
local Bobble = Vector3.new(GetBobbing(10), GetBobbing(5), GetBobbing(5))
local MouseDelta = game:GetService("UserInputService"):GetMouseDelta()
local Character = game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:Wait()
BobbleSpring:shove(Bobble / 10 * (Character.HumanoidRootPart.Velocity.Magnitude) / 10)
SwaySpring:shove(Vector3.new(-MouseDelta.X / 75, MouseDelta.Y / 75, 0))
local UpdatedRecoilSpring = RecoilSpring:update(dt)
local UpdatedBobbleSpring = BobbleSpring:update(dt)
local UpdatedSwaySpring = SwaySpring:update(dt)
viewmodel:SetPrimaryPartCFrame(viewmodel:GetPrimaryPartCFrame():ToWorldSpace(CFrame.new(UpdatedBobbleSpring.Y, UpdatedBobbleSpring.X, 0)))
viewmodel:SetPrimaryPartCFrame(viewmodel:GetPrimaryPartCFrame() * CFrame.new(UpdatedSwaySpring.X, UpdatedSwaySpring.Y, 0))
viewmodel:SetPrimaryPartCFrame(viewmodel:GetPrimaryPartCFrame() * CFrame.Angles(math.rad(UpdatedRecoilSpring.X), math.rad(UpdatedRecoilSpring.Y), 0))
workspace.Camera.CFrame *= CFrame.Angles(math.rad(UpdatedRecoilSpring.X), math.rad(UpdatedRecoilSpring.Y), math.rad(UpdatedRecoilSpring.Z))
end
function module.Shoot(Mouse, FirePos, FireCF, Attachment, RecoilSpring, Up, Sideways, Shake, Gun)
local plr = game.Players.LocalPlayer
local Cam = workspace.CurrentCamera
local Viewmodel = Cam:WaitForChild(Gun.Name)
local Ammo = Gun:GetAttribute("Ammo")
local OrgAmmo = Gun:GetAttribute("OriginalAmmo")
local RS = game:GetService("ReplicatedStorage")
local SS = game:GetService("SoundService")
local KillSound = SS:WaitForChild("KillSound")
local EXPsound = SS:WaitForChild("EXP")
local Background = plr.PlayerGui.Kill.Background
local KillPopup = plr.PlayerGui.Kill.KillPopup
local HeadPopup = plr.PlayerGui.Kill.HeadPopup
FirePos = Attachment.Position
FireCF = Attachment.CFrame
if Mouse.Target ~= nil then
local ShootEvent = RS.Events.Shoot:InvokeServer(Mouse.Hit.Position, false, FirePos, FireCF, Gun)
print(ShootEvent)
RecoilSpring:shove(Vector3.new(Up, math.random(-Sideways, Sideways), Shake)) -- Vector3.new(up, sideways, shake) // remember
coroutine.wrap(function()
task.wait(.1)
RecoilSpring:shove(Vector3.new(-(Up - .2), math.random(-(Sideways / 2), (Sideways / 2)), -Shake))
end)()
if ShootEvent == "Killed" then
KillSound:Play()
Kill_UI(Background, KillPopup)
EXPsound:Play()
end
if ShootEvent == "Headshot" then
KillSound:Play()
Kill_UI(Background, HeadPopup)
EXPsound:Play()
end
else
RS.Events.Shoot:InvokeServer(Mouse.Hit.Position, true, FirePos, FireCF, Gun)
RecoilSpring:shove(Vector3.new(Up, math.random(-Sideways, Sideways), Shake)) -- Vector3.new(up, sideways, shake) // remember
coroutine.wrap(function()
task.wait(.1)
RecoilSpring:shove(Vector3.new(-(Up - .2), math.random(-(Sideways / 2), (Sideways / 2)), -Shake))
end)()
end
end
Local Script (inside weapon tool)
RunService.RenderStepped:Connect(function(dt)
if Viewmodel then
MainModule.update(Viewmodel, dt, RecoilSpring, BobbleSpring, SwaySpring)
end
end)