extends Node2D

class_name Spline

var points : PackedVector2Array

var curve_points : PackedVector2Array

func get_point_at(distance : float):
	var current_point : int = 0
	while true:
		if current_point >= len(curve_points)-1:
			return null
			
		if distance > curve_points[current_point].distance_to(curve_points[current_point + 1]):
			distance -= curve_points[current_point].distance_to(curve_points[current_point + 1])
		else:
			return lerp(curve_points[current_point],curve_points[current_point+1], distance/(curve_points[current_point].distance_to(curve_points[current_point + 1])))
		
		current_point += 1
		
		if distance < 0:
			break
	
	return curve_points[current_point]
