actionscript-3rotationdegrees

Correct formula to "invert" rotation (in degrees) in AS3?


I have my player movieclip on the stage, and when the mouse is clicked a bullet is fired and projected at the correct angle to point itself at the mouse location. I also want a "mirroring" enemy, that fires at the complete opposite direction when the player does.

For example, when the player shoots upwards, the enemy should shoot down. Likewise, shooting to the right will cause the enemy to shoot to the left.

Is there a formula to convert the rotation in degrees to it's complete opposite?


Solution

  • Using Matrix is a very simple and exact solution. just multiple a or c with -1 ( to flip vertical and horizontal ).

    Sample code:

            var _tmpMatrix:Matrix = sprite.transform.matrix;
            _tmpMatrix.a *= -1;
            if ( _tmpMatrix.a < 0 ) {
                _tmpMatrix.tx = sprite.width + sprite.x;
            } else {
                _tmpMatrix.tx = 0;
            }
            sprite.transform.matrix = _tmpMatrix;