Hello,
I have a question, how do you make the camera shake like this?
Help is appreciated
Hello,
I have a question, how do you make the camera shake like this?
Consider using this module link (itās pretty good and very easy to implement, also it has a lot of features)
Call the Humanoid.CameraOffset
and use CFframes from the offset of an x and y axis. You can run it through a loop, maybe to the length of which the super attack (like the one shown above) can be used to denote when you actually want the camera to shake.
Humanoid.CameraOffset ā Refer to this
Or you could just directly call the camera object and have itās subject set to Humanoid (pretty much what Humanoid.CameraOffset
is, however, it does not necessarily have its subject be the humanoid.
When shifting through the cameraās Cframe/position, you maybe would want to use trigonometric functions like math.abs(math.sin())
or math.cos
(math.abs
is not trig function but certain sin results can yield negative numbers and we only want the position to shift positively). In those parameters, you can put tick()
to have a buffer of continuous time feeding in and giving an oscillating output.
It got me smth like this:
local RS = game:GetService("RunService")
local cam = workspace.CurrentCamera
local sin = math.sin
local abs = math.abs
RS.RenderStepped:Connect(function(dt)
cam.CFrame *= CFrame.new(abs(sin(tick() - dt)), 0 ,0)
end)
Should I remove the delta part?
How would I add intensity to the script?
Still wondering abt this
I tried to look at other devforum posts abt this, but the scripts they provided were not what I wanted
Oh wow, good on you for doing what you showed me above, perhaps to make the thinking process a bit easier, have each turn/oscillation be set to their own variables, because with that, from the variable itself, we can multiply it by a value to set more amplitude. For the rate of it ocurring, to make it faster, here is 2 things,
Sorry I responded late, was doing some instense gamer developing myself
Here is a example how you can do this:
And dont forget to put it in StarterCharacterScripts
local TweenService = game:GetService("TweenService")
local humanoid = game.Players.LocalPlayer.Character.Humanoid
local camera = workspace.CurrentCamera
local shakeIntensity = 2.9 -- Adjust this value to control the intensity of the shake
local shakeSpeed = 0.1 -- Adjust this value to control the speed of the shake
-- Function to shake the camera
function shakeCamera()
local shakeOffset = Vector3.new(
math.random(-shakeIntensity, shakeIntensity),
math.random(-shakeIntensity, shakeIntensity),
math.random(-shakeIntensity, shakeIntensity)
)
local originalOffset = humanoid.CameraOffset
local shakeTween = TweenService:Create(humanoid, TweenInfo.new(shakeSpeed), {
CameraOffset = originalOffset + shakeOffset
})
shakeTween:Play()
shakeTween.Completed:Wait()
humanoid.CameraOffset = originalOffset
end
while true do
-- Call the function to shake the camera
shakeCamera()
wait()
end
I wouldnāt want to use TweenServiceā¦ but thank you for the response.
Indeed, perhaps tween would look far to smooth, however you can use Exponential
easing to make it look smooth but still quick
Far to smooth and far too slow
No problem, i tried updating the code without using TweenService (simple way):
local humanoid = game.Players.LocalPlayer.Character.Humanoid
local camera = workspace.CurrentCamera
local shakeIntensity = 2.9 -- Adjust this value to control the intensity of the shake
local shakeSpeed = 0.1 -- Adjust this value to control the speed of the shake
-- Function to shake the camera
function shakeCamera()
local shakeOffset = Vector3.new(
math.random(-shakeIntensity, shakeIntensity),
math.random(-shakeIntensity, shakeIntensity),
math.random(-shakeIntensity, shakeIntensity)
)
local originalOffset = humanoid.CameraOffset
local currentTime = 0
local duration = shakeSpeed
while currentTime < duration do
local delta = currentTime/duration
humanoid.CameraOffset = originalOffset + shakeOffset * (1 - delta)
currentTime = currentTime + wait()
end
humanoid.CameraOffset = originalOffset
end
while true do
-- Call the function to shake the camera
shakeCamera()
wait()
end
you can change the shakeIntensity and shake speed
Oh I see what you did with your code, creative, nice
Alr, thank you for the help chrrr-_limit
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.