3 Replies Latest reply on May 26, 2009 7:33 AM by kglad

    Random movement

    thil
      Hi,

       

      I am trying to figure out a way to randomly move a ball inside a bigger circle. The motion has to be smooth and completely random.

       

      can any one help me on this?

       

      Thanks
      thil
        • 1. Re: Random movement
          kglad Adobe Community Professional & MVP

          you can use any tween class to tween your ball from its current position to a point interior to the larger circle.  the exact code will depend on whether you use the flash tween class or another one and whether you are using as2 or as3.

           

          the end tween-point should be:

           

          x:  (1-2*Math.round(Math.random())*(largeCircle.radius-ball.radius)*Math.random();

           

          y:  (1-2*Math.round(Math.random())*Math.sqrt((largeCircle.radius-ball.radius)*(largeCircle.ra dius-ball.radius)-(x*x))*Math.random();

           

          x+=largeCircle.x;

          y+=largeCircle.y;

          • 2. Re: Random movement
            thil Level 1

            Thanks for your reply Kgld. I didnt get this.. can u snd me the some coding if any?

             

            Regards

            thil

            • 3. Re: Random movement
              kglad Adobe Community Professional & MVP

              the exact code will depend on whether you use the flash tween class or another one and whether you are using as2 or as3.