0 votes
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?

Godot version Godot 4 beta 3
in Engine by (378 points)

1 Answer

0 votes

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.

by (29 points)

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:

ontimer_timeout: Tween invalid. Either finished or created outside scene tree.

Did I understand your answer wrong?

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.