Created
March 9, 2018 15:37
-
-
Save drhayes/b4877057c0e289871625d08e31c3a13e to your computer and use it in GitHub Desktop.
LÖVE camera shake
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
self.noiseFactor = self.noiseFactor + dt | |
-- self.trauma = math.min(1, self.trauma) - dt * config.camera.traumaFactor | |
self.trauma = math.max(0, self.trauma - dt * config.camera.traumaFactor) | |
if self.cameraTarget then | |
self.x = self.x + (self.cameraTarget.pos.x - self.x) * dt * self.slideFactor | |
self.y = self.y + (self.cameraTarget.pos.y - self.y) * dt * self.slideFactor | |
end | |
-- Shake based on trauma | |
local shake = self.trauma ^ 2 | |
local maxOffset, maxAngle = config.camera.shake.maxOffset, config.camera.shake.maxAngle | |
local x = self.x - maxOffset / 2 * shake + maxOffset * shake * love.math.noise(self.noiseFactor * 10) | |
local y = self.y - maxOffset / 2 * shake + maxOffset * shake * love.math.noise(self.noiseFactor * 11) | |
local r = self.r - maxAngle / 2 * shake + maxAngle * shake * love.math.noise(self.noiseFactor * 12) | |
self.camera:setPosition(x, y) | |
self.camera:setAngle(r) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment