How do I make the camera shake like this?

Hello,

I have a question, how do you make the camera shake like this?


Help is appreciated

5 Likes

Consider using this module link (itā€™s pretty good and very easy to implement, also it has a lot of features)

2 Likes

Call the Humanoid.CameraOffset and use CFframes from the offset of an x and y axis. You can run it through a loop, maybe to the length of which the super attack (like the one shown above) can be used to denote when you actually want the camera to shake.

Humanoid.CameraOffset ā† Refer to this

Or you could just directly call the camera object and have itā€™s subject set to Humanoid (pretty much what Humanoid.CameraOffset is, however, it does not necessarily have its subject be the humanoid.

Camera

When shifting through the cameraā€™s Cframe/position, you maybe would want to use trigonometric functions like math.abs(math.sin()) or math.cos (math.abs is not trig function but certain sin results can yield negative numbers and we only want the position to shift positively). In those parameters, you can put tick() to have a buffer of continuous time feeding in and giving an oscillating output.

1 Like

It got me smth like this:


Hereā€™s the script I used:

local RS = game:GetService("RunService")

local cam = workspace.CurrentCamera

local sin = math.sin

local abs = math.abs

RS.RenderStepped:Connect(function(dt)
	cam.CFrame *= CFrame.new(abs(sin(tick() - dt)), 0 ,0)
end)

Should I remove the delta part?
How would I add intensity to the script?

1 Like

Still wondering abt this :thinking:
I tried to look at other devforum posts abt this, but the scripts they provided were not what I wanted

1 Like

Oh wow, good on you for doing what you showed me above, perhaps to make the thinking process a bit easier, have each turn/oscillation be set to their own variables, because with that, from the variable itself, we can multiply it by a value to set more amplitude. For the rate of it ocurring, to make it faster, here is 2 things,

  • From what you showed of what you wanted from the game right from the start vs what you shown be just previously, I noticed that this one goes a bit longer in actual distance (which is why it also takes longer). Because of this, I reckon you should divide the value of which it goes along the x-axis by quite a bit, it will do the oscillation faster.

  • Along side this, you can also use Lerp in order to set the acceleration of the change in x-axis.

Sorry I responded late, was doing some instense gamer developing myself

1 Like

Here is a example how you can do this:
And dont forget to put it in StarterCharacterScripts

local TweenService = game:GetService("TweenService")
local humanoid = game.Players.LocalPlayer.Character.Humanoid
local camera = workspace.CurrentCamera

local shakeIntensity = 2.9  -- Adjust this value to control the intensity of the shake
local shakeSpeed = 0.1     -- Adjust this value to control the speed of the shake

-- Function to shake the camera
function shakeCamera()
	local shakeOffset = Vector3.new(
		math.random(-shakeIntensity, shakeIntensity),
		math.random(-shakeIntensity, shakeIntensity),
		math.random(-shakeIntensity, shakeIntensity)
	)
	local originalOffset = humanoid.CameraOffset
	local shakeTween = TweenService:Create(humanoid, TweenInfo.new(shakeSpeed), {
		CameraOffset = originalOffset + shakeOffset
	})
	shakeTween:Play()
	shakeTween.Completed:Wait()
	humanoid.CameraOffset = originalOffset
end

while true do
	-- Call the function to shake the camera
	shakeCamera()
	wait()
end
2 Likes

I wouldnā€™t want to use TweenServiceā€¦ but thank you for the response.

1 Like

Indeed, perhaps tween would look far to smooth, however you can use Exponential easing to make it look smooth but still quick

2 Likes

Far to smooth and far too slow

1 Like

No problem, i tried updating the code without using TweenService (simple way):

local humanoid = game.Players.LocalPlayer.Character.Humanoid
local camera = workspace.CurrentCamera

local shakeIntensity = 2.9  -- Adjust this value to control the intensity of the shake
local shakeSpeed = 0.1     -- Adjust this value to control the speed of the shake

-- Function to shake the camera
function shakeCamera()
	local shakeOffset = Vector3.new(
		math.random(-shakeIntensity, shakeIntensity),
		math.random(-shakeIntensity, shakeIntensity),
		math.random(-shakeIntensity, shakeIntensity)
	)
	local originalOffset = humanoid.CameraOffset
	local currentTime = 0
	local duration = shakeSpeed
	while currentTime < duration do
		local delta = currentTime/duration
		humanoid.CameraOffset = originalOffset + shakeOffset * (1 - delta)
		currentTime = currentTime + wait()
	end
	humanoid.CameraOffset = originalOffset
end

while true do
	-- Call the function to shake the camera
	shakeCamera()
	wait()
end
14 Likes

you can change the shakeIntensity and shake speed

2 Likes

Oh I see what you did with your code, creative, nice

2 Likes

Alr, thank you for the help chrrr-_limit

1 Like

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