4 Replies Latest reply on Apr 22, 2009 6:06 PM by kglad

    inconsistent rotation?

    shintashi Level 1

      Basically, Program A has a cannon that aims to line up with where-ever the mouse is pointing, in 360 degrees, and fires when the mouse is is clicked. Program B has an eye instead of a cannon that should in theory do similar functions when the capslock key is toggled, but instead only has a 90 degree range of motion from the Right of the eye toward the bottom (quadrant 4 only). Where did the ther 270 degrees of rotation disappear to?

       

       

      Program A

       

      posdX = 0;
      posdY = 0;

       

      onEnterFrame = function() {

       

             
            stick_mc._rotation = Math.atan2(posdY,posdX) * 180/Math.PI;
         
          posdX = Number(disk_mc._x - _xmouse);       
      posdY = Number(disk_mc._y - _ymouse);
          dX.text = Number(disk_mc._x - _xmouse);
          dY.text = Number(disk_mc._y - _ymouse);

      onMouseDown = function(){
          for(i=0;i<80;i++) {
          electrons = this["electron"+i];   
          var k:MovieClip = stick_mc.attachMovie("electron","electron"+i ,stick_mc.getNextHighestDepth());
          k._x -= Math.random()* 150 +30;            //plus changes distance of start of beam, base changes range
          k.gotoAndPlay(Math.ceil(Math.random()*16));  


                         
          } // end electron for loop

       

      }
          }

       

       

      --------------------

       

      Program B

       

      posdX = Number(robot_mc.laser_mc.lasereye_mc._x - _xmouse);       
              posdY = Number(robot_mc.laser_mc.lasereye_mc._y - _ymouse);
         

          if(Key.isToggled(Key.CAPSLOCK)){beamFire = true; counter = 2;
          robot_mc.laser_mc.lasereye_mc._rotation = Math.atan2(posdY,posdX) * 180/Math.PI;
         
          }
         
         
          if(beamOn == true || beamFire == true){
                     
             
      for(i=0;i<80;i++) {
          photons = this["photon"+i];   
          var k:MovieClip = robot_mc.laser_mc.lasereye_mc.attachMovie("photon","photon"+i ,robot_mc.laser_mc.lasereye_mc.getNextHighestDepth());
              k._xscale = Math.random()* 220 + 35;
          k._yscale = Math.random()* 120 - 20;
              k._x -= Math.random()* 15 +10;            //plus changes distance of start of beam, base changes range
         
          k.gotoAndPlay(Math.ceil(Math.random()*16));   
             
          } // end photon for loop

       

          } // end beamOn command

       

         

        • 1. Re: inconsistent rotation?
          kglad Adobe Community Professional & MVP

          there's nothing wrong with your code.

           

          use the trace() function to check the _rotation property and make sure it's correct, then check if there's a reg pt issue or something else preventing you from seeing the other rotations.

          1 person found this helpful
          • 2. Re: inconsistent rotation?
            shintashi Level 1

            you were right about the registration point being part of the problem,

             

             

            I ultimately had to turn the above bolded into this:

             

            posdX = Number(robot_mc._x - _xmouse + 19);       
                    posdY = Number(robot_mc._y - _ymouse - 38);

             

            When I created a dynamic textbox to track rotation (what I use instead of trace to debug - personal preference) I noticed the rotation was locked to a negative, but when experimenting with tan, 4*tan, 360/pi, etc., I came to the conclusion the rotation couldn't be repaired and was counting some "mysterious value". The mysterious value was the rotation eye itself. To correct this mistake, I used the robot body as the "grounding point" and then adjusted the coordinate according to the difference from the center of the eye to the center of the robot (trial and error guess work).

             

            The center is the eye now, and it works fine. Thank you for the suggestion, although I admit I didn't know what "reg pt" meant (I had to google it).

            • 3. Re: inconsistent rotation?
              shintashi Level 1

              had to use a non rotating mc to determine the relative rotation of an object.

              • 4. Re: inconsistent rotation?
                kglad Adobe Community Professional & MVP

                you're welcome.