0 votes

Navigation2D getsimplepath() 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.

asked Apr 2 in Engine by irmantus (15 points)

1 Answer

0 votes
Best answer

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.

answered Apr 3 by Magso (2,867 points)
selected Apr 5 by irmantus
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.