26 lines
702 B
GDScript
26 lines
702 B
GDScript
extends Node3D
|
|
|
|
@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 _process(delta: float):
|
|
if trauma:
|
|
trauma = max(trauma - shake_decay * delta, 0)
|
|
trauma_time += 4096 * delta
|
|
_shake(trauma_time)
|
|
else:
|
|
rotation = Vector3.ZERO
|
|
trauma_time = 0
|
|
|
|
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) |