![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | pferft |
Hi everyone,
my Sprite
jumps from its current position to another random position quite nicely:
func _ready():
randomize()
yield(get_tree().create_timer(rand_range(0.5,2)), "timeout")
var x_position = rand_range(-10, 4)
var y_position = rand_range(-7, 4)
position = Vector2(x_position, y_position)
_ready()
I’d like that jumping to change into smooth moving and I thought a Tween
would do the trick, so I tried this:
func _ready():
randomize()
yield(get_tree().create_timer(rand_range(0.5,2)), "timeout")
var x_position = rand_range(-10, 4)
var y_position = rand_range(-7, 4)
#position = Vector2(x_position, y_position) # greyed out because I don't want a jump to the new position
var tween = Tween.new()
add_child(tween)
tween.interpolate_property(self, "position",
x_position, y_position, 1,
Tween.TRANS_EXPO, Tween.EASE_OUT)
tween.start()
tween.connect("tween_all_completed",tween,"queue_free")
_ready()
However like that the Sprite
doesn’t move at all (or does it, just to the same position?). Any idea what I’m missing here?