Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

How to rotate nested movieclips properly?

New Here ,
Mar 11, 2014 Mar 11, 2014

I have a tank which has a nested movieclip called Barrel.

Barrel successfully faces the player, unless the tank itself rotates.

So it only works if the tank doesn't rotate.

I need to find a way to make the rotation work, and I googled and found:

    var rot:Number = rotation, p:DisplayObjectContainer = parent, s:DisplayObjectContainer =     stage;

    while (p != s) {

      rot += p.rotation;

      p = p.parent;

    }

But I have no idea how to implement this in my current code:

    // calculate rotation based on target

                                        _dx = this.x - _root.hero.x;

                                        _dy = this.y - _root.hero.y;

    // which way to rotate

                                        _rotateTo = getDegrees(getRadians(_dx, _dy));

 

    // keep rotation positive, between 0 and 360 degrees

                                        if (_rotateTo > barrel.rotation + 90) _rotateTo -= 360;

                                        if (_rotateTo < barrel.rotation - 90) _rotateTo += 360;

 

    // ease rotation

                                        _trueRotation = (_rotateTo - barrel.rotation) /     _rotateSpeedMax;

   

    //barrel rotation

                barrel.rotation += _trueRotation;

I tried changing

    barrel.rotation += _trueRotation;

to

    barrel.rotation += _trueRotation + parent.rotation

after reading online that you can simply add all the rotations, but it doesn't seem to work.

How can I implement

    var rot:Number = rotation, p:DisplayObjectContainer = parent, s:DisplayObjectContainer =         stage;

    while (p != s) {

      rot += p.rotation;

      p = p.parent;

    }

into my code?

TOPICS
ActionScript
266
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 12, 2014 Mar 12, 2014
LATEST

just show the code you're using (that's relevant).  in particular, where's getRadians?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines