summaryrefslogtreecommitdiff
path: root/Camera2D.gd
blob: a86c6922128a4a0f545f2c76480c6d2248671c24 (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
extends Camera2D

onready var path : Path2D = get_node(@"../Path2D")
onready var points = path.curve.get_baked_points()
export var speedup = 600
export var speedup_time = 5
export var initial_speed = 100
onready var current_speed = initial_speed
var pidx = 0
var t = 0

func _process(delta):
	if pidx == -1:
		return
	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