blob: ede4484d84386ce017cf19efd0773a4b46b90efa (
plain)
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
39
40
41
42
43
44
45
46
47
48
49
|
extends Camera2D
class_name CameraTrackFollower
var path : Path2D setget set_path
signal done()
var _points
func set_path(value):
path = value
current_speed = 0
if path == null:
_points = []
_pidx = -1
else:
_pidx = 0
_t = 0
_points = value.curve.get_baked_points()
print("New path set to CameraTrackFollower")
export var speedup = 100
export var speedup_time = 5
export var initial_speed = 100
var current_speed = initial_speed
var _pidx = -1
var _done_emitted = true
var _t = 0
func _process(delta):
if _pidx == -1:
if not _done_emitted:
emit_signal("done")
_done_emitted = true
return
else:
_done_emitted = false
var next_point = _points[_pidx]
var dist : Vector2 = next_point - position
if _t < speedup_time:
current_speed += speedup * max(0, min(speedup_time-_t, delta))
_t += delta
if dist.length() - current_speed * delta < 0.5:
position = next_point
_pidx += 1
if _pidx >= _points.size():
_pidx = -1
_process(delta - dist.length() / current_speed)
return
var velocity = dist.normalized() * current_speed * delta
position += velocity
|