+1 vote

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.

in Engine by (21 points)

1 Answer

+1 vote
Best answer

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")
by (1,656 points)
selected by
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.