What do you want to achieve? Keep it simple and clear!
topic name explains everything
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
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)
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.
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.