Randomize speed and starting frame of animated sprites.

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By FezMonki

Hello, new at godot and programming in general.
Is there a way by any chance to randomize the speed and starting frame of each instance of a node based on the same scene, but all different? I tried a couple things but they all affected all nodes the same way.

I basically have a water animation bobbing up and down and I think it would look tremendously better if it was randomized. The best I could do was a second set with inverted order of animation but I want it a bit more sleek.

:bust_in_silhouette: Reply From: Eric Ellingson

This is assuming you are using the AnimationPlayer:

func play_randomized(animation_name : String):
	randomize()
	$AnimationPlayer.play(animation_name)
	var offset : float = rand_range(0, $AnimationPlayer.current_animation_length)
	$AnimationPlayer.advance(offset)

So then for example, if you have an animation called “water_bobbing”, you could call this function like:

play_randomized("water_bobbing")