There probably is a way to do it, but what it is I'm not totally sure. It also depends on what you are wanting to achieve, and how your scene(s) is setup.
If you are wanting to compare against the origin of the scene in global space, then using global_transform.origin.z instead of translation.z should work.
If you want to use another point in global space, then you will need to do some math to get the difference from the starting point, and then use that. Without testing, something like this might work, though there is probably a better way to do it:
var starting_point = Vector3(0,0,0)
const MAX_DISTANCE = 100
func _ready():
starting_point = get_global_transform.origin
# Other code here...
func update_animation():
var distance_from_starting_pos = global_transform.origin.z - starting_point.z
# Use abs so the distance from the starting pos is not negative
distance_from_starting_pos = abs(distance_from_starting_pos)
# Assure the distance is not over the maximum
if (distance_from_starting_pos > MAX_DISTANCE):
distance_from_starting_pos = MAX_DISTANCE
# Convert to 0-1 range
var relative_distance = distance_from_starting_pos / MAX_DISTANCE
# then set the position of the animation using the stored animation
# length and the relative Z pos (same code as the example above)
animation_player.seek(relative_z_pos * animation_length, true)
The only problem with this code is that the animation will only return back to normal as it gets closer to the starting position, but any movement away from the starting position in any direction on the Z axis will play/scrub the animation.
Hopefully this helps :smile: