Tween/lerp on Navigation2D

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By irmantus

Navigation2D get_simple_path() returns navigation nodes and I can lerp from one node to another, but how can I lerp or tween whole path. I.e. RTS style space ship should build up speed at start and slow down at the end of the path.

:bust_in_silhouette: Reply From: Magso

You can use the PathFollow node by adding the returned path to the curve2D on a Path2D node.

for i in navigation_path.size():
    Path2D.curve.add_point(navigation_path[i])
#and use this in _process
PathFollow2D.unit_offset = lerp(PathFollow2D.unit_offset, 1, delta)

Without a PathFollow2D you can’t use a single lerp or tween but you can lerp through the array using lerps like this

lerp_num = lerp(lerp_num, navigation_path.size()-1, delta)
sprite.position = lerp(navigation_path[int(lerp_num/(int(lerp_num)+0.01))], navigation_path[int(lerp_num/(int(lerp_num)+1))], lerp_num/(int(lerp_num)+0.01))

The +0.01 is so it’s not dividing by zero.