system
October 21, 2022, 3:45pm
1
Attention
Topic was automatically imported from the old Question2Answer platform.
Asked By
Godot_Starter
func move_body_part():
var tween :Tween = get_tree().create_tween()
tween.tween_property(self,"position",Vector2.RIGHT * 16, 0.5)
I am having this function, which gets called every 0.5 seconds, but I am only seeing a movement the first time it gets called, rather then a continious movement to the right. What am I doing wrong?
system
October 22, 2022, 8:28am
2
Reply From:
lakshaya
I think this is by design.
Can you try giving the tween a global scope, and calling tween.kill() at the beginning of this function.
So instantiate the tween globally, and just do tween.kill() and tween.tween_property() in this function.
Thank you for your response! Unfortunatly, I dont really get what you mean.
I tried modifiying the function like this:
func move_body_part():
Globals.tween.kill()
Globals.tween.tween_property(self,"position",Vector2.RIGHT * 16, 0.5)
and adding a autoloaded script like this:
#Globals
@onready var tween :Tween = get_tree().create_tween()
but now it doesnt moves to the right at all and instead, I am getting this error whenever I try to call the function:
_on_timer_timeout: Tween invalid. Either finished or created outside scene tree.
Did I understand your answer wrong?
Godot_Starter | 2022-10-22 12:40