Tween.set_loops() doesn't seem to work

Godot Version

v4.3.stable.official [77dcf97d8]

Question

Hey there, I’m still quite new to GDscript and programming in general, but I’m trying to put my coursework into practice. I’ve learned that the set_loops() member function is supposed to loop a tween indefinitely if called without an argument. However, the function I’ve written will only rotate the node once and halt. Where am I going wrong?

func play_spin_animation() → void:
var asteroid := get_node(“.”)
var revolution := 2 * PI
var duration := 3.0
create_tween().set_loops().tween_property(asteroid, “rotation”, revolution, duration)

It will rotate to 2 * PI, then the next loop it will try to rotate to 2 * PI, which it is already at. Add the .from() function to set a start and end point to loop.

As a side note it’s better to use self instead of $"."

var tween := create_tween().set_loops()
tween.tween_property(self, "rotation", revolution, duration).from(0.0)
2 Likes

Awesome, thanks for the explanation! Haven’t learned about .from() yet.