+1 vote

I tried to make Path2D and PathFollow2D with Godot 4. As there are some differences between Godot 3 I was not able to figure out how to do that. (Examples from Godot 3 are not working.)

I guess the tree structure will be the same:

Path2D
---PathFollow2D
------VisibleObject <- Script goes here   

Script will have the variables similar set, but what has to be written in the _process?

@onready
var path_follow = get_parent()
var speed = 10

func _process(delta):
    # what goes here?
Godot version 4
in Engine by (45 points)

1 Answer

+1 vote
Best answer

In Godot 4, offset changed to progress. So your code can be:

@onready var _follow :PathFollow2D = get_parent()
var _speed :float = 120.0

func _physics_process(delta):
    _follow.set_progress(_follow.get_progress() + _speed * delta)

If you want to go with Tweens (which is better), you'll want to use that way:

@onready var _follow :PathFollow2D = get_parent()

func _ready():
  _follow.progress_ratio = 0

  var tween :Tween = create_tween().set_trans(Tween.TRANS_SINE).set_ease(Tween.EASE_IN_OUT)
  tween.tween_property(_follow, 'progress_ratio', 1, 1)
by (58 points)
selected by

Both is working. Super answer, thank you.

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.