# Path3D, Curve3D curve direction in code to continue relatively where previous curve ends

### Question

Hi! Cant figure this out. I have Path3D object containing pre made curves. In code I am combining these to one bigger curve. It works, but I cant get curve elements to continue to the same direction where previous one stops. Everything else works fine. How on earth I have to do this, so it works? I have direction Vector3. It works, but I cant get correct numbers in. I am calculating the point locations by distance and direction.
This is the current test code for this:

var points_t =

``````var i = 0;
var base_direction = Vector3(0,0,0)
var main_direction = Vector3(0,0,0)

points.append({"position"=Vector3(0,0,0)})
for x in points.size():
var start = points[i].position
var end = points[i+1].position
if end != Vector3(0,0,0):
var direction = get_direction(start,end)
var distance = get_distance(start,end)

var destination = get_destination(start,direction,distance)
if points_t.size() >= 2:
var m_start = points_t[points_t.size()-2].position;
var m_end = points_t[points_t.size()-1].position;
main_direction = get_direction(m_start,m_end)
var dir = direction
#dir -= direction.cross(main_direction)
#dir += base_direction
destination = get_destination(m_end,dir,distance)
points_t.append({"position"=Vector3(destination)})
#print("start: ",start,", end:",end)
if points[i+1].position == Vector3(0,0,0):
i+=1
base_direction = main_direction
#print("L")
i +=1
if i+1 >= points.size():break
points = points_t
return points;
``````

edit: and here are the base funcs:

func get_destination(start: Vector3, dir: Vector3, dis: float) → Vector3:
var nd = dir.normalized()
var dest = start + nd * dis
return dest

func get_distance(p1,p2) → float:
var distance = p1.distance_to(p2)
return distance

func get_direction(p1,p2) → Vector3:
var line_dir = (p2 - p1).normalized()
return line_dir

edit #2
I think I got it - just use rotated when new block is added. Bonus rotation should be added on every step - this works at least on some point:
if new_block:
new_block = false;
bonus_angle = direction.angle_to(base_direction)
direction = get_direction(start,end)
direction = direction.rotated(Vector3(0, 1, 0), bonus_angle)

#edit: bonus angle should be increased on every round. Atleast if curve is rotating on same direction.