Last active
May 29, 2022 23:18
-
-
Save amirrajan/12e7d2d4d950b6ffe68fbaab038e44f3 to your computer and use it in GitHub Desktop.
DragonRuby Game Toolkit - Camera Shake (https://www.youtube.com/watch?v=-i1ILZsIqbU&ab_channel=AmirRajan)
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
def calc_camera | |
if player_charging? | |
if player_charge_percentage < 0.2 | |
state.camera.trauma += 0.005 | |
elsif player_charge_percentage < 0.5 | |
state.camera.trauma += 0.01 | |
elsif player_charge_percentage < 0.8 | |
state.camera.trauma += 0.02 | |
else | |
state.camera.trauma += 0.04 | |
end | |
end | |
if state.camera.trauma < 0.3 | |
state.camera.x_offset = 0 | |
state.camera.y_offset = 0 | |
state.camera.angle = 0 | |
else | |
next_camera_angle = 180.0 / 20.0 * state.camera.trauma**2 | |
next_offset = 100.0 * state.camera.trauma**2 | |
state.camera.angle = state.camera.angle > 0 ? | |
next_camera_angle * -1 : | |
next_camera_angle | |
state.camera.x_offset = rand >= 0.5 ? | |
next_offset * rand : | |
next_offset * rand * -1 | |
state.camera.y_offset = rand >= 0.5 ? | |
next_offset * rand : | |
next_offset * rand * -1 | |
state.camera.trauma *= 0.95 | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment