-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCamera_Script.gd
More file actions
38 lines (24 loc) · 778 Bytes
/
Camera_Script.gd
File metadata and controls
38 lines (24 loc) · 778 Bytes
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
37
38
extends Camera2D
onready var shakeTimer = $Timer
onready var tween = $Tween
var shake_amount = 0
var default_offset = offset
func _ready():
GlobalCamera.camera = self
set_process(false)
func _process(delta):
offset = Vector2(rand_range(-shake_amount, shake_amount), rand_range(-shake_amount, shake_amount)) * delta + default_offset
func shake(new_shake, shake_time=0.4, shake_limit=100):
shake_amount += new_shake
if shake_amount > shake_limit:
shake_amount = shake_limit
shakeTimer.wait_time = shake_time
tween.stop_all()
set_process(true)
shakeTimer.start()
func _on_Timer_timeout():
shake_amount = 0
set_process(false)
tween.interpolate_property(self, "offset", offset, default_offset,
0.1, Tween.TRANS_QUAD, Tween.EASE_IN_OUT)
tween.start()