Created
April 24, 2025 04:52
-
-
Save jgdovin/40255a61adee589ba6fc7684b7f79ce3 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
extends Camera2D | |
@export var decay : float = 0.8 | |
@export var max_offset: Vector2 = Vector2(100, 75) | |
@export var max_roll : float = 0.1 | |
@export var follow_node : Node2D | |
var trauma : float = 0.0 | |
var trauma_power : int = 2 | |
var max_trauma : float = 1.0 | |
func _ready() -> void: | |
randomize() | |
Game.damage_taken.connect(_on_damage_taken) | |
func _on_damage_taken() -> void: | |
add_trauma(0.5) | |
func _process(delta: float) -> void: | |
if follow_node: | |
global_position = follow_node.global_position | |
if trauma: | |
trauma = max(trauma - decay * delta, 0) | |
_shake() | |
func add_trauma(amount : float) -> void: | |
trauma = min(trauma + amount, max_trauma) | |
func _shake() -> void: | |
var amount = pow(trauma, trauma_power) | |
rotation = max_roll * amount * randf_range(-1, 1) | |
offset.x = max_offset.x * amount * randf_range(-1, 1) | |
offset.y = max_offset.y * amount * randf_range(-1, 1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment