2 Replies Latest reply on Jul 1, 2010 12:50 PM by rHemanth

    smooth rotation

    kamlam4 Level 1

      I want to make a movieclip moves smoothly,

      and when it changes the direction, it can turn smoothly but not a sudden turn, can anyone help?

       

      I try out the code below. and the truning is odd:

      this.rotation = (Math.atan2(targetY-this.y, targetX-this.x )/Math.PI)*180;

        • 1. Re: smooth rotation
          rHemanth Level 2

          Lengthy but brings some smoothness .

          Create a movie clip movie clip movieClip_1

           

          var num:Number = 5;

          var num2:int =90;

           

          var smoothnessControl:Number = 30;

          var num3:int = num2/smoothnessControl;

          movieClip_1.addEventListener(Event.ENTER_FRAME, fl_RotateContinuously_2);

          var timer:Timer;

           

          function fl_RotateContinuously_2(event:Event)

          {

          if(movieClip_1.x>500 ){

           

          movieClip_1.removeEventListener(Event.ENTER_FRAME, fl_RotateContinuously_2);

          setTimer()

          }

           

           

          movieClip_1.x += num;

           

           

           

           

          }

           

          function fl_RotateContinuously_3(event:Event)

          {

          movieClip_1.y+= num;

          }

           

          function setTimer():void{

          timer = new Timer(15,smoothnessControl);

          timer.addEventListener(TimerEvent.TIMER,rotate);

          timer.addEventListener(TimerEvent.TIMER_COMPLETE,addLis);

          timer.start();

          }

           

          function rotate(event):void{

          movieClip_1.rotation+=num3;

          movieClip_1.x+=0.5;

          movieClip_1.y+=0.5;

          }

           

          function addLis(event):void{

          timer.removeEventListener(TimerEvent.TIMER,rotate);

          timer.removeEventListener(TimerEvent.TIMER_COMPLETE,addLis);

          movieClip_1.addEventListener(Event.ENTER_FRAME, fl_RotateContinuously_3);

          }

           

          fla can be found here http://www.4shared.com/file/_Ubduiva/Untitled-1.html

          • 2. Re: smooth rotation
            rHemanth Level 2

            Do mail me if u find a better method,i am sure there are many