Question

I'm at a complete loss at how to do this:

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?

Thanks, - Ryan

Was it helpful?

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;

OTHER TIPS

Wouldn't adding or subtracting 180 degrees point in the opposite direction?

or

obj.scaleX = -1;

will do the same thing. =)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top