17 Replies Latest reply on Jun 1, 2007 11:23 AM by Sketchsta

    Random Flying Code??

    Sketchsta Level 1
      Hi guys, I have taken on this project for a Sadako Sasaki Website Intro,( Fold 1000 Paper Cranes fo Peace Charity ) and they want a bunch of Cranes flying around, and one of the cranes to carry a Flag sort of Message sayin Make Cranes For Peace...or something like that.. anyway... im looking for any ideas on code for flying cranes around the stage, preferably in a random fashion, and random size too.

      I want this Intro to look as realistic as possible ( not the cranes themselves ) but the way the cranes MOVE ..
      have already made the animation for the cranes to Flap their wings, i just need some help with code to make them MOVE and STOP at random locations and sizes.

      Thanx in advance to anyone willing to help.
        • 1. Re: Random Flying Code??
          kglad Adobe Community Professional & MVP
          check the flash implementations of craig reynolds boids if you want to utilize flock behavior.
          • 2. Re: Random Flying Code??
            Sketchsta Level 1
            Thats wayyy too indepth... I didnt mean i want the cranes to be THAT realistic..

            what i meant was, i want them to face the right way when moving, or while they aren;t moving, to stop animating the flapping of the wings.

            This is all i meant about realistic...Craig Reynolds is taking it to the MAX.. i dont need that much realism, they ARE paper cranes after all. =)

            Thanx for pointing him out tho, definately gonna read more from him. I love maths, but i suck at it, so i need all the learning i can get.
            • 3. Re: Random Flying Code??
              kglad Adobe Community Professional & MVP
              the easiest thing would be to have your cranes start from off-stage and fly to another location off-stage and have them fly in a straight line. it would probably look best to have them fly left-to-right or vice versa.

              you could limit their start and stop _y properties to be random numbers between 0 to whateverY and fix their starting _x to about -crane._width and ending _x to be Stage.width+crane._width or vice versa.

              you could randomize their size within certain limits and you could randomize their color. you could randomize the frequency of a new crane appearing. all that should be pretty straight-forward.
              • 4. Re: Random Flying Code??
                Rothrock Level 5
                kglad, why do you know so many interesting things that I don't have the spare time to follow up with them. That boids looks sooooo cool.

                As for the cranes, I've been doin some things with fish lately and the tween class is very helpful. Especially if you combine different easing functions to the x and y. My current favorite is a compination of Elastic.eastOut and Back.easeOut. It makes some interesting "school" like behavior.
                • 5. Re: Random Flying Code??
                  kglad Adobe Community Professional & MVP
                  i just love to learn things. i always have.

                  and i'm old. so, i've learned a lot of things.
                  • 6. Re: Random Flying Code??
                    Rothrock Level 5
                    Ah, that's right. You have a biiiiigggg start on me. :) Okay, well a bit. I hope to be as cool as you one day.
                    • 7. Re: Random Flying Code??
                      Sketchsta Level 1
                      Hey thanx for the suggestions, i'll get started and see how i go with them now that i've finished the BG.

                      however, i do need abit of help for the BG too..

                      First of all....Im REALLLLY REALLLLY bad at Maths, as you can probably tell from the code, but it does the job. But i find it abit frustrating because the BG never sits still, unless it reaches the end, so i was wondering how i can make the BG not move when the mouse is close to the center of the stage.

                      • 8. Re: Random Flying Code??
                        kglad Adobe Community Professional & MVP
                        when the absolute value of speed1 and/or speed2 are less than some number set them to zero.
                        • 9. Re: Random Flying Code??
                          Sketchsta Level 1
                          ohhh kool... see i told you i suck at maths. even something that simple i couldnt think about... Im ashamed...

                          its all good now. Thanx for that. =)

                          now, about the cranes, here is what i have so far, and unfortunately i havent gotten any furtherer in the last hour or so... i been trying to get all the cranes to follow 1 tween...but with no luck..
                          I can only get one crane to follow the tween, and as far as i know, it's the last crane to be added by the for loop.

                          ( i know im out of my league here, but im trying to use some of the things i learnt from the carousel you helped me with before. )

                          • 10. Re: Random Flying Code??
                            kglad Adobe Community Professional & MVP
                            your tween is outside your for-loop.
                            • 11. Re: Random Flying Code??
                              Sketchsta Level 1
                              ohhhh WTH!!!!

                              i thought it's not supposed to be in the for loop..
                              sheesh... I really suck.. =(

                              ok last question, before i go hide my face in shame...
                              how can i check which way a crane is moving? Left or right.
                              I wanna make the cranes face the right way when they move.
                              • 12. Re: Random Flying Code??
                                kglad Adobe Community Professional & MVP
                                the easiest way would be to generate that Math.random()*900 number outside of your tween constructor, check if it's greater than or less than bird._x and use the _xscale=-100 if you need to turn your bird.
                                • 13. Re: Random Flying Code??
                                  Sketchsta Level 1
                                  That worked great, and it got me thinking in a different way too... I love it when it's soo simple..

                                  so im hoping this is something simple too. I have the cranes coming on stage at random positions, and tweening to random positions, for both _x and _y. I want the cranes to continue to tween to random positions, which i thought would be as simple as using

                                  yoyo()

                                  but that doesnt seem to work... i added traces on the yoyo() command to see if they are being called, which they are, continuously, but the cranes are not moving.

                                  am I missing something?? or am i doing something wrong..?
                                  • 14. Re: Random Flying Code??
                                    Sketchsta Level 1
                                    hmm.... forget the yoyo() method.... i just realised its not exactly what im looking for..

                                    but i do still need a constant animation happening...
                                    • 15. Re: Random Flying Code??
                                      kglad Adobe Community Professional & MVP
                                      try:

                                      • 16. Re: Random Flying Code??
                                        Sketchsta Level 1
                                        ohh, continueTo() i forgot alll about that, i remember i read about it before in the "not so helpful" Flash docs.. Thanx for reminding me, thats working good now.

                                        but im having problems getting the cranes to turn again. I used what you suggested ( checking current position and destination..then _xscale it to minus ) but that doesnt seem to work when the continueTo() is happening.

                                        I tried to add the if() statement inside each onMotionFinished() functions, but that didnt work. even tried adding the variables used in the statement...but nothing. The if() statement isn't being called.

                                        how can i get this to keep checking that if() statement?
                                        • 17. Re: Random Flying Code??
                                          Sketchsta Level 1
                                          Ok, Im back on this project, but still no luck. I cant get the if() statement to trigger from the continueTo() method.

                                          the first time i call the Tweens, it works, the if() statement is working fine....but once the tween finishes and the continueTo() method starts, the if() statement isnt working.

                                          I tried using a variable i created OUTSIDE the onMotionFinished function, but that just makes all the cranes goto the same place.
                                          I tried to create new variables INSIDE the onMotionFinished function, along with the if() statement, but that doesnt work either...


                                          The if() statement is VITAL, i need it to be working so that if it's met, the cranes face the opposite way. As it is now, the if() statement only happens on the first Tween, and NOT for the continueTo() method.

                                          Am i doing something really wrong here?? or am i missing something?