How would I make this kind of recoil?

I currently have a function in a module script that essentially just moves the camera up and then down a bit. I’ve tried regular tweens but that does not seem to work because of the camera system which is ran in a renderstepped event.

Any help would be useful, thanks.

3 Likes

Can you show me the script? I’d be able to help you better that way

1 Like

sure. i’ll send the whole camera module i have

local UserInputService = game:GetService('UserInputService')
local TweenService = game:GetService('TweenService')

local rootpartinfo = TweenInfo.new(.1, Enum.EasingStyle.Linear, Enum.EasingDirection.In)
local n_rootpartinfo = TweenInfo.new(.01, Enum.EasingStyle.Linear, Enum.EasingDirection.In)
local fovininfo = TweenInfo.new(.3, Enum.EasingStyle.Linear, Enum.EasingDirection.In)
local fovoutinfo = TweenInfo.new(.2, Enum.EasingStyle.Linear, Enum.EasingDirection.Out)

local CameraSystem = {}

function CameraSystem.LOCK_CAMERA(rootPart, camera, player, CURRENTROOTPARTTWEEN, bool)
	
	TweenService:Create(camera, fovininfo, {FieldOfView = 50}):Play()
	
	player.CameraMinZoomDistance = 8
	player.CameraMaxZoomDistance = 8
	--TweenService:Create(camera, lockinfo, {CFrame = camera.CFrame * CFrame.new(2.7,0.6,1)}):Play()
	camera.CFrame = camera.CFrame * CFrame.new(3,0.8,.5)
	local camLv = camera.CFrame.lookVector
	local camRotation = math.atan2(-camLv.X, -camLv.Z)
	--[[if player.Character.Humanoid.MoveDirection.Magnitude > 0 then
		CURRENTROOTPARTTWEEN = TweenService:Create(rootPart, n_rootpartinfo, {CFrame = CFrame.new(rootPart.Position) * CFrame.Angles(0, camRotation, 0)}):Play()
	else
		CURRENTROOTPARTTWEEN = TweenService:Create(rootPart, rootpartinfo, {CFrame = CFrame.new(rootPart.Position) * CFrame.Angles(0, camRotation, 0)}):Play()
	end]]
	rootPart.CFrame = CFrame.new(rootPart.Position) * CFrame.Angles(0, camRotation, 0)
	if CURRENTROOTPARTTWEEN then
		CURRENTROOTPARTTWEEN:Play()
	end
	return CURRENTROOTPARTTWEEN
end

function CameraSystem.UNLOCK_CAMERA(camera, player, CURRENTROOTPARTTWEEN)
	
	if camera.FieldOfView ~= 70 then
		TweenService:Create(camera, fovoutinfo, {FieldOfView = 70}):Play()
	end
	player.CameraMinZoomDistance = 8
	player.CameraMaxZoomDistance = 20
	
	if CURRENTROOTPARTTWEEN then
		CURRENTROOTPARTTWEEN:Stop()
	end
	
end

function CameraSystem.RECOIL(recoiltime, recoilreturntime, recoilpower, recoilreturnpower, camera)
	for i = 1, recoiltime do
		--camera.CFrame = camera.CFrame:Lerp(camera.CFrame * CFrame.fromEulerAnglesXYZ(math.rad(recoilpower-((recoiltime-i)/30)),0,0), 0.1)
		camera.CFrame = camera.CFrame * CFrame.fromEulerAnglesXYZ(math.rad(recoilpower-((recoiltime-i)/30)),0,0)
		task.wait(0.0000000000001)
	end
	for i = 1, recoilreturntime do
		camera.CFrame = camera.CFrame * CFrame.fromEulerAnglesXYZ(-math.rad(recoilreturnpower),0,0)
		task.wait(0.001)
	end
end

return CameraSystem

2 Likes

i cant see the vid, because the error above.
(even if im using a normal browser that normally lets you see vids), in what format is it? .mp4?

1 Like

TweenService:GetValue() could be used there, since it turns a number value from 0 to 1 and tween options into a tweened number from 0 to 1.

2 Likes

This will take a bit of setting up (super easy). But in the end you will have a very good camera shaker system. It comes with some presets and you can add custom shakes. I use this in Unity also, it has always been rock solid. When it’s all set up a shake comes down to a one line command.

ez-camera-shake

2 Likes

The video format is .MOV, you can just download it to see it.

2 Likes

I can’t download it, there is no download button.

2 Likes

Press the three dots, and then hit download.

Here is the video converted to the Mp4 format.

1 Like

Yeah I know, but the ‘download’ doesnt appear for some reason.
Don’t worry, it lets me see .mp4, so I dont need to download it.

2 Likes

As I said, TweenService:GetValue() is useful for tweening when the camera is bound to the RenderStepped event. You can also use CFrame:Lerp() if it’s too hard to implement.

1 Like

thanks. i used it and it works well.

3 Likes

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