Skip to content
This repository has been archived by the owner on Jul 28, 2022. It is now read-only.

Commit

Permalink
Add StopSustained to CameraShaker
Browse files Browse the repository at this point in the history
  • Loading branch information
Sleitnick committed Dec 12, 2019
1 parent 31325d2 commit cad55bc
Showing 1 changed file with 23 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
CameraShaker:Start()
CameraShaker:Stop()
CameraShaker:StopSustained([fadeOutTime])
CameraShaker:Shake(shakeInstance)
CameraShaker:ShakeSustain(shakeInstance)
CameraShaker:ShakeOnce(magnitude, roughness [, fadeInTime, fadeOutTime, posInfluence, rotInfluence])
Expand All @@ -33,22 +34,16 @@
-- Custom shake:
camShake:ShakeOnce(3, 1, 0.2, 1.5)
wait(1)
-- Sustained shake:
local swayShakeInstance = CameraShaker.Presets.GentleSway
camShake:ShakeSustain(swayShakeInstance)
wait(3)
camShake:ShakeSustain(CameraShaker.Presets.Earthquake)
-- Sustained shake fadeout:
swayShakeInstance:StartFadeOut(3)
-- "CameraShaker.Presets.GentleSway" or any other preset
-- will always return a new ShakeInstance. If you want
-- to fade out a previously sustained ShakeInstance, you
-- will need to assign it to a variable before sustaining it.
-- Stop all sustained shakes:
camShake:StopSustained(1) -- Argument is the fadeout time (defaults to the same as fadein time if not supplied)
-- Stop only one sustained shake:
shakeInstance = camShake:ShakeSustain(CameraShaker.Presets.Earthquake)
wait(2)
shakeInstance:StartFadeOut(1) -- Argument is the fadeout time
NOTE:
Expand All @@ -57,6 +52,8 @@
permission by the developer, Road Turtle Games, to port this to Roblox.
Original asset link: https://assetstore.unity.com/packages/tools/camera/ez-camera-shake-33148
GitHub repository: https://github.com/Sleitnick/RbxCameraShaker
--]]
Expand Down Expand Up @@ -129,6 +126,15 @@ function CameraShaker:Stop()
end


function CameraShaker:StopSustained(duration)
for _,c in pairs(self._camShakeInstances) do
if (c.fadeOutDuration == 0) then
c:StartFadeOut(duration or c.fadeInDuration)
end
end
end


function CameraShaker:Update(dt)

local posAddShake = v3Zero
Expand All @@ -145,8 +151,9 @@ function CameraShaker:Update(dt)
if (state == CameraShakeState.Inactive and c.DeleteOnInactive) then
self._removeInstances[#self._removeInstances + 1] = i
elseif (state ~= CameraShakeState.Inactive) then
posAddShake = posAddShake + (c:UpdateShake(dt) * c.PositionInfluence)
rotAddShake = rotAddShake + (c:UpdateShake(dt) * c.RotationInfluence)
local shake = c:UpdateShake(dt)
posAddShake = posAddShake + (shake * c.PositionInfluence)
rotAddShake = rotAddShake + (shake * c.RotationInfluence)
end

end
Expand Down Expand Up @@ -199,4 +206,4 @@ function CameraShaker:StartShake(magnitude, roughness, fadeInTime, posInfluence,
end


return CameraShaker
return CameraShaker

0 comments on commit cad55bc

Please sign in to comment.