summaryrefslogtreecommitdiff
path: root/components/CameraTrackFollower.gd
diff options
context:
space:
mode:
authorrom <romangraef@gmail.com>2021-04-25 15:38:57 +0200
committerrom <romangraef@gmail.com>2021-04-25 15:41:42 +0200
commita8d0cd8b68131251cf07fff6fd01817012f23d8a (patch)
treed7830ee11ca91c13308c5b6fb5e8c38b9c09c727 /components/CameraTrackFollower.gd
parent65da988ee9536858ef9975becb739ba24c695aea (diff)
downloadldjam48-a8d0cd8b68131251cf07fff6fd01817012f23d8a.tar.gz
ldjam48-a8d0cd8b68131251cf07fff6fd01817012f23d8a.tar.bz2
ldjam48-a8d0cd8b68131251cf07fff6fd01817012f23d8a.zip
base level loading
Diffstat (limited to 'components/CameraTrackFollower.gd')
-rw-r--r--components/CameraTrackFollower.gd45
1 files changed, 45 insertions, 0 deletions
diff --git a/components/CameraTrackFollower.gd b/components/CameraTrackFollower.gd
new file mode 100644
index 0000000..22420d9
--- /dev/null
+++ b/components/CameraTrackFollower.gd
@@ -0,0 +1,45 @@
+extends Camera2D
+class_name CameraTrackFollower
+var path : Path2D setget _path
+
+signal done()
+
+var _points
+func _path(value):
+ path = value
+ _pidx = 0
+ _t = 0
+ _points = value.curve.get_baked_points()
+ current_speed = 0
+ _done_emitted = false
+ 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
+ var next_point = _points[_pidx]
+ var dist : Vector2 = next_point - position
+ print("Camera movement", dist)
+ 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
+