Godot 2D : Make a tween move up and down

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

Hello! I want to make a tween move up and down ( this tween will be a trap and it’s moving up and down only on Y axis). The problem is that my node moves from up- to down and get back to its place (up) and stops. I want it to continuously move up and down. Do you know how to do it? I tried to use a timer but I didn’t succed.

export var move_to = Vector2.DOWN *600
export var speed = 6.0
var follow= Vector2.ZERO

onready var tween = $Tween

func _ready():

func _physics_process(delta):
platform.position= platform.position.linear_interpolate(follow,0.075)

func _init_tween():
tween.interpolate_property(self,“follow”,move_to, Vector2.ZERO, 3, Tween.TRANS_LINEAR, Tween.EASE_IN_OUT, 2)

Can you edit your post and use the code sample tag (mark code, press the icon with “{ }”), to make it easier to read?

Becbunzen | 2020-06-02 17:53

:bust_in_silhouette: Reply From: migraman

You said it’s already going down and back up, right? The problem here is the loop. Try using the “While” function with a variable(or constant)

var loop = true
Func ready():
While loop == true:

I guess this will keep the Tween looping

Hello, thanks for the answer. If I use while in _ready() function my application crashes , but otherwise it seemed like a good idea .

Riri | 2020-06-03 14:51

:bust_in_silhouette: Reply From: estebanmolca

Here they explain it well:


If there is something you don’t understand, comment.

Thank you, it was helpfull. I only needed to connect func _on_tween_completed(object, key) and to re-call _inittween() .

Riri | 2020-06-03 14:48