How to move the generated nodes into a specific direction smoothly and slowly?

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

I wrote a script to spawn nodes for my game and this game is an endless runner so I want to move my nodes into a specific direction.

func spawn():
	var energy_scene = load("res://scenes/energy.tscn")
	var energy = energy_scene.instance()
	var random = Vector2(rand_range(30,230),30)

    #energy.set_position(Vector2(random.x,500)) --> but it goes directly to that location without speed, without animation
:bust_in_silhouette: Reply From: Eric Ellingson

You can use a Tween

You can either add a Tween node to your scene tree, or create one manually. Either way, you can then do something like:

    energy, // node to operate on
    "position",  // property to change
    random, // initial value
    Vector2(random.x,500), // final value
    1, // duration, in seconds
    Tween.TRANS_LINEAR, // interpolation function, see
    Tween.EASE_IN, // easing function, see
    0, delay, in seconds

thanks that will do the work

Shlopynoobnoob | 2019-12-19 18:55