I want to know how to make Pathfollow run backwards.

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

The code here works fine, and the object moves along the path.

How can I make it go in the opposite direction?

extends Path2D

onready var follow=get_node("PathFollow2D")

func _ready():
set_process(true)

func _process(delta):
follow.set_offset(follow.get_offset()+350*delta)
:bust_in_silhouette: Reply From: kidscancode

FYI, set_process(true) hasn’t been required since Godot 2. You may be looking at very old documentation/tutorials.

offset is the distance that the Pathfollow2D is located along the path. Your code, more succinctly written as:

follow.offset += 350 * delta

Is increasing that value by that amount every frame. To go backwards, you would just subtract instead of adding.

If you start with offset = 0, you’ll be at the start of the path. To start at the end, you need to get the length of the curve:

follow.offset = curve.get_baked_length()

WHAT, HOW DO YOU DO TO HAVE AN ANWSER QUICKLY

Lgdn | 2021-08-21 17:25

@Lgdn kidscancode is an ever-present legendary genius, that’s why! :stuck_out_tongue:

timothybrentwood | 2021-08-22 14:37