Random timer in animation not working

I have two animation on one sprite object.

I want to play animation 1.
When animation 1 is finished I want to change animation to animation 2 and start a random timer between 5 and 10 seconds.
When the timer is finished I want to start animation 1 again and then a new timer then it’s finished.

I have tested with this, the animation change but I always get about 5 second. I also tested: RandomFloatInRange(5,100) to make it more extreme but same result, about 5 seconds.

You need to save the random number to a variable and then check the variable instead of picking a new random number on each frame. At a targeted 60 frames a second, a new number will be picked 60 times per second. It will most likely pick the number 5 before the timer reaches 6 seconds. It’s a bit like a brute force attempt to crack a password.

You can use an object variable. Set the variable to a random number in range at the beginning.

If timer >= variable
Then do something and set the variable to a new random number in range, start/reset timer

1 Like