Make a camera shake ONLY in a certain area

Ok so… following idea. I want to make a camera shake script. And it activates when you click a part. But now my next idea:
It only activates when in a certain area. Let’s say… it only shakes the camera inside an invisible part. Any ideas on how to script this?

4 Likes

How about using a Region3 instead of a part and make a function that returns whether you’re in the region or not before shaking:

2 Likes

If you need a camera shake script I recommend using sleitnick’s module EZ Camera Shake

2 Likes

Thanks, now the only thing left is to make the shake stop when I leave the certain area I mentioned. Any ideas?

Well there is a :Stop() function in the module.

1 Like

But how do I check if a player left the area? I don’t know where to put the Region3 stuff in the script.

you would just constantly check if a mesh of the humanoid is in there. But bro there is an easier way, just use magnitude

1 Like

What do you mean “activates in a certain area”, you mean the player’s perspective switches to the part then it shakes?

1 Like

Use the same function you make to detect if the player is in the region to see if he is still in the region?

How are you planning to trigger the shake to begin with? Once triggered you’ll need to monitor the status and trigger the stop.

1 Like

Hello! As @AWhale_OfATime mentioned, I would recommend using sleitnick’s EZ Camera Shake module.

Next the only other problem you’ll encounter with this problem is detecting when the camera is inside of a certain region. The easiest method in doing this is probably using Magnitude. A simple script to do something like this:

local Players = game:GetService("Players")

local CameraShaker = game.ReplicatedStorage.CameraShaker -- Reference the EZ Camera Shake module

local Camera = workspace.CurrentCamera

local camShake = CameraShaker.new(Enum.RenderPriority.Camera.Value, function(shakeCf)
	camera.CFrame = camera.CFrame * shakeCf
end)

local centerPart = game.workspace.Part -- Reference to around where you want the camera to shake
local distanceToPart = 50 -- The distance around the part you want the camera to shake in

camShake:Start()

while true do
    if (Camera.CFrame.Position - centerPart.CFrame.Position).Magnitude < distanceToPart then
        camShake:ShakeSustain(CameraShaker.Presets.HandheldCamera)
    else
        camShake:StopSustained(2)
    end
end

For further explanation, centerPart is the center of where you want the shaking effect to have effect. And distanceToPart is the radius around that part where the shaking effect will happen.

Hopefully this fits your needs. Let me know if you encounter any issues.

6 Likes

This is EXACTLY what I wanted. Thank you so much!
But now I get this weird problem:

new is not a valid member of the ModuleScript "ReplicatedStorage.CameraShaker"

And thanks to all the people that helped me too!

Oh! In order to access the contents of a ModuleScript, you have to require() it, so put game.ReplicatedStorage.CameraShaker into a require. require(game....).

1 Like

Okay; Either I’m dumb or I’m not, but uhm… the camera won’t even shake… No errors, no nothing.
I don’t know what to do and I’m very very confused lmfao