–1 vote

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)
Godot version 3.3.2
in Engine by (10 points)

1 Answer

0 votes

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()
by (21,979 points)

WHAT, HOW DO YOU DO TO HAVE AN ANWSER QUICKLY

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

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.