Topic was automatically imported from the old Question2Answer platform.
Asked By
Losatu
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?
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)
Both is working. Super answer, thank you.
Losatu | 2022-11-27 20:42
Ok, thanks in advance for helping me to better understand how it works, but how do I go from just one point to another point, without following a straight line with more than 2 points?