Godot Version
Godot 4.6.dev5
Question
I’m currently trying to make some animations using tweens. What I want to achieve is the final value of the tween_property being modified for every loop of the tween, but it seems the variable is only passed once and doesn’t update between loops.
I’ve tried several approaches, but nothing that produces any difference. Below is an example snippet - not my actual use case but identical logic:
var first_loop_add: float = 1
var last_loop_add: float = 10 # Would actually be 10-0.9 which is fine.
var loops: int = 10
var tween : Tween = create_tween().set_loops(loops)
var tween_progress01 : float = 1 - inverse_lerp(0.0, loops, tween.get_loops_left())
tween.tween_property(self, "position:y", lerp(first_loop_add, last_loop_add, tween_progress01), 1.0).as_relative()
tween.loop_finished.connect(
func on_loop_finished(_count: int) -> void:
print(str(tween.get_loops_left())) # Prints 9, 8 ... 1
print("Current pos y: " + str(position.y)) # Prints 1.0, 2.0 ... 9.0
print("Progress from variable ref = " + str(tween_progress01)) # Prints 0.0 every time
)
In this example starting from (0,0,0), I would expect the final position value to be (0, 50.5, 0), with 50.5 being the sum of each successive interpolations (1 + 1.9 + 2.8 … + 9.1).
From what I gather, the value is only passed at the start and never updated.
I could of course add as much tweens as I’d like with manually inputted values. The below also works, but is horrendous:
var seq: Tween = create_tween()
for i in loops:
var t: Tween = create_tween()
var t01: float = inverse_lerp(0.0, loops, i)
t.tween_property(self, "position:y", lerp(first_loop_add, last_loop_add, t01), 1.0).as_relative()
seq.tween_subtween(t)
Is there any clean way to achieve this using tweens, or are my expectations just wrong about this?
Thanks!