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?
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:
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.
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
What do you mean “activates in a certain area”, you mean the player’s perspective switches to the part then it shakes?
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.
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.
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....)
.
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