Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into fix-sequent-type
Browse files Browse the repository at this point in the history
bdidk235 authored Jan 2, 2025

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
2 parents 4bd66c3 + 7c7a5ea commit d4e8f51
Showing 1 changed file with 29 additions and 4 deletions.
33 changes: 29 additions & 4 deletions modules/shake/init.luau
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
--!native

-- Shake
-- Stephen Leitnick
-- December 09, 2021

local RunService = game:GetService("RunService")

--[=[
@@ -78,6 +74,35 @@ local renderId = 0
Shakes will automatically stop once the shake has been completed. Shakes can
also be used continuously if the `Sustain` property is set to `true`.
## Fixing drift
If you are not controlling the initial CFrame of the camera (i.e. using Roblox's camera scripts),
then you might run into odd behavior with the above example. This is because Roblox's camera
scripts are influenced by the current CFrame value of the camera. Thus, the shake effect causes
odd side-effects, especially noticeable at higher FPS.
The solution is to simply store the camera's CFrame before applying the shake CFrame, and then
reapplying this stored CFrame value after rendering is complete (e.g. on Heartbeat).
```lua
local camCf: CFrame
shake:BindToRenderStep(Shake.NextRenderName(), priority, function(pos, rot, isDone)
-- Store the CFrame value that was set from Roblox's camera scripts:
camCf = camera.CFrame
camera.CFrame *= CFrame.new(pos) * CFrame.Angles(rot.X, rot.Y, rot.Z)
end)
RunService.Heartbeat:Connect(function()
-- Reapply the camera script CFrame before they run again.
-- Heartbeat runs AFTER Roblox has rendered, so it will not affect the camera this frame.
camera.CFrame = camCf
end)
```
## Configuration
Here are some more helpful configuration examples:
```lua

0 comments on commit d4e8f51

Please sign in to comment.