Added camera shake

This commit is contained in:
Eduard Urbach 2024-02-07 23:02:27 +01:00
parent c81cc97e87
commit 97087ad03e
Signed by: akyoto
GPG Key ID: C874F672B1AF20C0

View File

@ -8,9 +8,16 @@ extends Camera3D
@export var follow_enabled: bool @export var follow_enabled: bool
@export var follow_speed: float @export var follow_speed: float
@export_group("Shake")
@export var shake_strength := 1.0
@export var shake_decay := 0.8
@export var shake_noise: Noise
var trauma := 0.0
var trauma_time := 0.0
func _ready(): func _ready():
Global.camera = self Global.camera = self
look_at(pivot_node.position)
func _process(delta): func _process(delta):
if Global.player == null: if Global.player == null:
@ -21,12 +28,19 @@ func _process(delta):
else: else:
follow_node.position = Global.player.position follow_node.position = Global.player.position
# @export var shake_strength: float if trauma:
# var noise = FastNoiseLite.new() trauma = max(trauma - shake_decay * delta, 0)
# func shake(time): trauma_time += 4096 * delta
# var trauma_sq := 1.0 _shake(trauma_time)
# var h_offset := noise.get_noise_2d(time, 0) * trauma_sq * shake_strength else:
# var v_offset := noise.get_noise_2d(time, 1) * trauma_sq * shake_strength look_at(pivot_node.global_position)
# rotate_x(noise.get_noise_2d(time, 2) * trauma_sq * shake_strength) trauma_time = 0
# rotate_y(noise.get_noise_2d(time, 3) * trauma_sq * shake_strength)
# rotate_z(noise.get_noise_2d(time, 4) * trauma_sq * shake_strength) func _shake(time):
var trauma_sq := trauma * trauma
rotation.x += shake_noise.get_noise_2d(time, 0) * trauma_sq * shake_strength
rotation.y += shake_noise.get_noise_2d(time, 1) * trauma_sq * shake_strength
rotation.z += shake_noise.get_noise_2d(time, 2) * trauma_sq * shake_strength
func add_shake(amount: float):
trauma = min(trauma + amount, 1.0)