-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcamera.gd
36 lines (30 loc) · 1004 Bytes
/
camera.gd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
extends Camera3D
var shake_intensity: float = 1.0
var shake_decay: float = 0.5
var shaking: bool = false
var has_shaken: bool = false
var original_transform
func _ready():
original_transform = global_transform
func _process(delta: float) -> void:
if shaking:
# Apply random offset to the camera's position
var rand_vector = randf_range(-shake_intensity, shake_intensity)
var random_offset = Vector3(rand_vector, rand_vector, rand_vector)
global_transform.origin = original_transform.origin + random_offset
# Reduce the shake intensity over time
shake_intensity -= shake_decay * delta
if shake_intensity <= 0.0:
shaking = false
shake_intensity = 0.0
global_transform = original_transform
# Function to start the camera shake
func start_shake(intensity: float, decay: float):
if has_shaken:
return
has_shaken = true
shaking = true
shake_intensity = intensity
shake_decay = decay
# Save the current transform as the original
original_transform = global_transform