This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
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.

in Engine by (15 points)

1 Answer

+1 vote
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.

by (3,259 points)
selected by
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 Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.