36 lines
835 B
GDScript
36 lines
835 B
GDScript
extends Node
|
|
|
|
signal unfreeze
|
|
|
|
const END_VALUE: int = 1
|
|
|
|
var is_active: bool = false
|
|
var time_start: int
|
|
var duration_ms: int
|
|
var start_value: float
|
|
|
|
|
|
func start(duration: int = 1, strength: float = 0.9):
|
|
time_start = OS.get_ticks_msec()
|
|
duration_ms = duration * 1000
|
|
start_value = 1 - strength
|
|
Engine.time_scale = start_value
|
|
is_active = true
|
|
|
|
|
|
func _process(_delta: float) -> void:
|
|
if is_active:
|
|
var current_time = OS.get_ticks_msec() - time_start
|
|
var value = circl_ease_in(current_time, start_value, END_VALUE, duration_ms)
|
|
if current_time >= duration_ms:
|
|
is_active = false
|
|
value = END_VALUE
|
|
emit_signal('unfreeze')
|
|
Engine.time_scale = value
|
|
return
|
|
|
|
|
|
func circl_ease_in(t, b, c, d):
|
|
t /= d
|
|
return -c * (sqrt(1 - t * t) - 1) + b
|