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")
	randomize()
	var energy = energy_scene.instance()
	var random = Vector2(rand_range(30,230),30)
	energy.set_position(random)
	$energies.add_child(energy)

    #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:

$Tween.interpolate_property(
    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 https://docs.godotengine.org/en/3.1/classes/class_tween.html#enum-tween-transitiontype
    Tween.EASE_IN, // easing function, see https://docs.godotengine.org/en/3.1/classes/class_tween.html#enum-tween-easetype
    0, delay, in seconds
)
$Tween.start()

thanks that will do the work

Shlopynoobnoob | 2019-12-19 18:55