Good evening,
Can someone help me to script a Part.
I want if the Player touches the Part that the Cam zooms in and the screen starts shaking and if the Player dont touch the Part it stops.
I don’t know how to script with camera shakes so can somebody help me?
1 Like
Create a LocalScript inside of StarterCharacterScripts, then copy and paste this code within the newly founded local script that you have just created.
Code:
Took 20 minutes to complete, hope you’re welcome.
local players = game:GetService("Players")
local runService = game:GetService("RunService")
local playerInTable = {}
local player = players.LocalPlayer
local character = player.Character
local defaultCameraOffset = character.Humanoid.CameraOffset
local camera = game.workspace.CurrentCamera
local defaultFOV = camera.MaxAxisFieldOfView
local cameraCFrame = camera.CFrame
local part = game.Workspace.Part -- replace this part with the part that you want..
-- to test the part, you could create a new part in workspace, then step on it..
local shakeValue = 0.5 -- higher value means more shake..
local zoomValue = 50 -- lower value means more zoomed in.. (default FOV is around 100+)
part.Touched:Connect(function(character)
local humanoid = character.Parent:FindFirstChild("Humanoid")
if humanoid then
playerInTable[humanoid] = true
end
end)
part.TouchEnded:Connect(function(character)
local humanoid = character.Parent:FindFirstChild("Humanoid")
if humanoid then
playerInTable[humanoid] = nil
camera.MaxAxisFieldOfView = defaultFOV
end
end)
runService.RenderStepped:Connect(function()
for humanoid in pairs(playerInTable) do
if humanoid.MoveDirection.Magnitude == 0 then
for i = 0, shakeValue * 10 do
local offset = Vector3.new(math.random(-1, 1), math.random(-1, 1), math.random(-1, 1))
character.Humanoid.CameraOffset = character.Humanoid.CameraOffset:Lerp(offset, shakeValue * 0.25)
end
camera.MaxAxisFieldOfView = zoomValue
elseif humanoid.MoveDirection.Magnitude ~= 0 then
for i = 0, shakeValue * 10 do
local offset = Vector3.new(math.random(-1, 1), math.random(-1, 1), math.random(-1, 1))
character.Humanoid.CameraOffset = character.Humanoid.CameraOffset:Lerp(offset, shakeValue * 0.25)
end
camera.MaxAxisFieldOfView = zoomValue
end
end
end)
character.Humanoid.CameraOffset = defaultCameraOffset
Does work, but expect bugs.
1 Like
Dude, thank you sooo much for this this helps me alot. God bless you my man and have a nice Day/Night. Dm me when you need anything
1 Like
No problem, glad/happy to help.
1 Like
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.