Kon-Tiki |
Does anyone know if it's possible and, if it is, how to randomly animate an object? I'm trying to make someone who stands still, do the same action at random. For example: A bird stands on some hay. It should start picking in the hay at random. If it isn't possible, then does anyone know how to (again, an example) make two birds (the same views) pick the hay on different moments? |
jelleghys |
You'll have to make two (or more) loops Loop no 0: bird does nothing Loop no 1: bird does animation Then:
So the first if-block picks a random number between (inc.) 0 and 20. When the random number is 20 (1 chance out of 21) the bird object will be set in loop number 1 and animate until it reaches the last cel (bird_end_of_loop will then be set). The second if-block will test if bird_end_of_loop is set, if so, it will reset the bird_is_doing_animation flag and put the bird back again in loop number 0. Something like that??? |
jelleghys |
The bird_is_doing_animation flag is necesary if you don't want the bird-animation being set up when the bird is already being animated... Of course, if you want the bird being animated more often, you'll have to change the 20 in the random-thing: random(0,20,v100); => 1 chance out of 21 random(0,100,v100); => 1 chance out of 101 random(0,10,v100); => 1 chance out of 11 |
Kon-Tiki |
Hmmm, this isn't quite what it should be. This is a random event every time you enter the room. It should be a random event in the room (so it happens more than once when you're in the room.) Consider it as a bird which is looking around for food (while standing still), and, when it thinks it has found something, it should try and eat it, just to restart this from the beginning when finished. |
jelleghys |
If you put the 2 if-blocks AFTER the if(isset(f5)){}block, the animation will occure (at random) more than once in a room (without leaving the room)...
|
Kon-Tiki | :) Thanks :) It's working perfect now. |
Joel |
You should probably reset the bird_end_of_loop flag inside if (bird_end_of_loop) so that you code doesn't keep setting the bird's loop to 0. It probably won't hurt it to leave it as it is, but it's a little cleaner, and besides...resetting the flag will keep you in the habit of resetting flags with end.of.loop which will help you avoid bugs later on. |
jelleghys |
Good remark!If it isn't possible, then does anyone know how to (again, an example) make two birds (the same views) pick the hay on different moments? If you want the birds picking hay on different moments (not random), you just have to set different cels to start with:
But after all, I think the random stuff is much nicer to look at. This thing above will probably look very unnatural. |
Kon-Tiki |
Thanks, the random works fine now, but I have another problem. The wander doesn't work. Here's my logic:
What this gives, is the same as Bug in Tryout. The captain walks at the same spot as where he is positioned, but he doesn't change direction or move from that spot. Does someone know how to fix this? |
Joel |
If that is a direct copy of your code, then the problem is that the code to position the "kapitein" object is outside of the new_room block. Change your code so it looks like this:
|
Kon-Tiki | Thanks. (Seems like I make a lot of these mistakes ::), but now I'm getting the hang of it.) |