hey guys, as the title says, how would I achieve this?
this is what I’m trying to achieve:
this is what I originally wrote: (this errors actually)
function camStuff.GradualScreenshake(
humanoid: Humanoid,
duration: number,
intensity: number
)
local startTime = tick()
local value = nil
intensity *= 100
value = math.floor(intensity / (duration * 10) )
repeat
task.wait()
local endTime = tick()
local xoffset = math.random(-intensity, intensity) / 500
local yoffset = math.random(-intensity, intensity) / 500
local zoffset = math.random(-intensity, intensity) / 500
humanoid.CameraOffset = Vector3.new(xoffset, yoffset, zoffset)
intensity = math.ceil(intensity * 0.5)
until endTime - startTime >= duration
humanoid.CameraOffset = Vector3.new(0, 0, 0)
end
this is what my friend wrote for me
Friend's code
local curve = Instance.new("FloatCurve")
curve:InsertKey(
FloatCurveKey.new(0, 0, Enum.KeyInterpolationMode.Cubic)
)
curve:InsertKey(
FloatCurveKey.new(0.1, 1, Enum.KeyInterpolationMode.Cubic)
)
curve:InsertKey(
FloatCurveKey.new(0.75, 0.1, Enum.KeyInterpolationMode.Cubic)
)
curve:InsertKey(
FloatCurveKey.new(1, 0, Enum.KeyInterpolationMode.Cubic)
)
local RunService = game:GetService("RunService")
function camStuff.GradualScreenshake(
humanoid: Humanoid,
duration: number,
intensity: number?
)
local timer = 0
local targetCameraOffset = Vector3.zero
local bind = RunService.RenderStepped:Connect(function(dt)
humanoid.CameraOffset = humanoid.CameraOffset:Lerp(targetCameraOffset, math.clamp(dt*32, 0, 1))
end)
repeat
local scale = math.clamp(timer / duration, 0, 1)
-- 0 to 1
local curvedIntensity = curve:GetValueAtTime(scale)
local dt = task.wait(1/60)
timer += dt
local evaulated = timer * curvedIntensity
local offset = Vector3.new(
(math.random() - 0.5) * 2,
(math.random() - 0.5) * 2,
(math.random() - 0.5) * 2
) * curvedIntensity * (intensity or 1)
targetCameraOffset = offset
until timer >= duration+0.1
bind:Disconnect()
RunService.RenderStepped:Wait()
humanoid.CameraOffset = Vector3.zero
end
but just doesn’t yield the results I want, could anybody give me tips on how to achieve the one shown in the video I linked? thanks so much! ![]()