How to make my recoil effect more smooth when moving

I have this to make the game be in isometric view point (from the corner basically) and I have a recoil effect in it to move the camera when they hold left click, and while this works it’s very jittery and jerky when moving while shooting but it looks decent when standing still.

local Players = game:GetService("Players")
local RunService = game:GetService("RunService")

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local eventsFolder = ReplicatedStorage.Events

local StarterPlayer = game.StarterPlayer
local player = Players.LocalPlayer
local camera = workspace.CurrentCamera

local mouse = player:GetMouse()

local CAMERA_DEPTH = 30
local HEIGHT_OFFSET = 3
local NORMAL_FIELD_OF_VIEW = 30

camera.FieldOfView = NORMAL_FIELD_OF_VIEW

local function onWheelBackward()
	if CAMERA_DEPTH < 50 then
		CAMERA_DEPTH = CAMERA_DEPTH + 2
	end
end
mouse.WheelBackward:Connect(onWheelBackward)

local function onWheelForward()
	if CAMERA_DEPTH > 30 then
		CAMERA_DEPTH = CAMERA_DEPTH - 2
	end
end
mouse.WheelForward:Connect(onWheelForward)

local function updateCamera()
	local character = player.Character
	if character then
		local root = character:FindFirstChild("HumanoidRootPart")
		if root then
			local rootPosition = root.Position + Vector3.new(0, HEIGHT_OFFSET, 0)
			local cameraPosition = rootPosition + Vector3.new(CAMERA_DEPTH, CAMERA_DEPTH, CAMERA_DEPTH)
			camera.CFrame = CFrame.lookAt(cameraPosition, rootPosition)
		end
	end
end

local cam = workspace.CurrentCamera
local TS = game:GetService("TweenService")

local recoilDirection = Vector3.new(0, 0.5, 0) -- Adjust the recoil direction
local recoilIntensity = 1 -- Adjust the recoil intensity

local function recoil()
	local oldCFrame = cam.CFrame
	local newCFrame = oldCFrame * CFrame.Angles(math.rad(recoilDirection.X * recoilIntensity), math.rad(recoilDirection.Y * recoilIntensity), math.rad(recoilDirection.Z * recoilIntensity))

	local tweenInfo = TweenInfo.new(0.1, Enum.EasingStyle.Quint, Enum.EasingDirection.Out)
	local tweenProperties = {CFrame = newCFrame}

	local recoilTween = TS:Create(cam, tweenInfo, tweenProperties)
	recoilTween:Play()

	-- Snap back to original position after recoil
	wait(0.1)
	local resetTween = TS:Create(cam, tweenInfo, {CFrame = oldCFrame})
	resetTween:Play()
end

eventsFolder.RecoilEvent.OnClientEvent:Connect(recoil)

RunService:BindToRenderStep("IsometricCamera", Enum.RenderPriority.Camera.Value + 1, updateCamera)

heres the whole code but the part to focus on mostly is just the recoil function, I’ve tried tweening and Cframe with this working the best out of them but with it not working to well when moving, any way to fix this?

I recommend not using the Tween for recoil,(at least for my case) The Tween final position is unchanged, basically if you fire your game at point A, the camera will jump to point B but if you are moving at that time, the camera still jumps to point B and not update to your position.

I use the Spring Module, it is easy to use once you get used to it, and it has a lot of more settings you can customize, be sure to check out the desmo page to know what each value does.

2 Likes

I took a look at it but I cant for the life of me figure it out, I like the look of my current recoil effect its just so jerky when moving even if I try to update it to the current position. Is there a way to just make it always tween from position to position to make moving smooth without using the Spring Module?

1 Like

been working at it found its just easiest with how my camera is setup to just adjust the Fov to move slightly when firing, thanks for the suggestion though!

2 Likes

Yeah, it is not an instant click to use the module. Definitely take some time.
Glad that you have found your own way

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.