Ok, so for the for
, just think of it as a complicated while
in that case it would be doing something like:
var nodes = get_all_nodes()
var node = nodes[0] #first node
var index = 0 #where are we
while index < nodes.size() # go through all the nodes in the list
#do something
index += 1 # increment index so we leave the loop at some time
About your problem, so you want to execute once per animation frame, so basically, if doing in the _process
method you would:
func _process(delta):
if special_animation_is_playing() && distancebetween < 10:
transform.origin = transform.origin.linear_interpolate(transform.origin + Vector3(0,0,20),time)
So that would the simple way and it should work, try it first and improve your code later. On another note, think about moving this function into the physicsprocess(), check this other question for an explanation why.
Now for the improvement, i didn't play much with the animation player and it's calls, so I can't give you an answer, but what you want seems to be a signal or a method call that is executed every keyframe of an animation, and done by animation itself. I suggest you hit the docs or make another question specifically for that.