How to make camera shake effect of Scriptable camera which CFrame changed to some part CFrame

  1. What do you want to achieve? Keep it simple and clear!
    topic name explains everything
  2. What is the issue? Include screenshots / videos if possible!
    Simple methods of doing this like Humanoid.CameraOffset don’t work there, because camera is not locked to humanoid ig
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub? i’ve tryed looking some posts about this but nothing found

Code:

--REMOTE EVENTS
local BuildingCamera = workspace.Events.BuildingCamera


--CAMERA STUFF
local cc = workspace.CurrentCamera


--PLAYER
local Player= game:GetService("Players").LocalPlayer


--START

BuildingCamera.OnClientEvent:Connect(function(BuildingName, toggle)
	print("received. Toggle - "..toggle)
	local building = workspace.FirstMap.Buildings:FindFirstChild(BuildingName)
	if toggle == "Enable" then
		local bc = building.BuildingCamera
		cc.CameraType = Enum.CameraType.Scriptable
		cc.CFrame = bc.CFrame
		building.Effects.Smoke.Enabled = true
		while true do


			local xOffset = math.random(-100, 100) / 500
			local yOffset = math.random(-100, 100) / 500
			local zOffset = math.random(-100, 100) / 500

			Player.Character.Humanoid.CameraOffset = Vector3.new(xOffset, yOffset, zOffset)
			task.wait()
		end
		Player.Character.Humanoid.CameraOffset = Vector3.new(0, 0, 0)
	elseif toggle == "Disable" then
		cc.CameraType = Enum.CameraType.Custom;
		building.Effects.Smoke.Enabled = false
	end
end)
1 Like

To create the camera shake effect, you can add a small piece of code inside the while true loop. The code snippet can be inserted just before “task.wait()” in the provided code. Here is the updated code:

while true do
    local xOffset = math.random(-100, 100) / 500
    local yOffset = math.random(-100, 100) / 500
    local zOffset = math.random(-100, 100) / 500

    Player.Character.Humanoid.CameraOffset = Vector3.new(xOffset, yOffset, zOffset)

    -- Adicione o código a seguir para trepidar a câmera
    local shakeIntensity = 0.01 -- Intensidade do tremor
    local shakeSpeed = 10 -- Velocidade do tremor

    local shakeOffset = Vector3.new(math.sin(tick() * shakeSpeed) * shakeIntensity, math.cos(tick() * shakeSpeed) * shakeIntensity, 0)
    cc.CFrame = cc.CFrame * CFrame.new(shakeOffset)

    task.wait()
end

In this code, we add a value of intensity (shakeIntensity) and speed (shakeSpeed) to control camera shake. The camera will be randomly moved using the xOffset, yOffset and zOffset offsets as before. In addition, we apply additional camera shake motion by multiplying its CFrame by an offset (shakeOffset) that varies over time. The math.sin and math.cos functions are used to create a smooth oscillating motion.

Try this.

1 Like

It kinda not shaking and just spinning like if it was welded to hinge point with motor mode :confused:

EDIT: This one for humanoid camera is making cool shake effect

while true do
			local xOffset = math.random(-100, 100) / 500
			local yOffset = math.random(-100, 100) / 500
			local zOffset = math.random(-100, 100) / 500

			Player.Character.Humanoid.CameraOffset = Vector3.new(xOffset, yOffset, zOffset)

could i smhw remake this one to work with your code?

2 Likes

Yes!

If the camera shake effect is not working as expected and the camera is spinning instead of shaking, it is possible that the issue is related to the use of Humanoid’s CameraOffset. CameraOffset is used to apply an offset to the camera based on the character’s position, but it is not suitable for creating a realistic judder effect.

An alternative approach to creating a more convincing judder effect is to apply the offset directly to the camera’s CFrame. You can do this by tweaking the code inside the while true loop.

2 Likes

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