# Problems with movieclip rotation within subclasses

**URL:** https://forum.kirupa.com/t/problems-with-movieclip-rotation-within-subclasses/276331
**Category:** programming
**Created:** [November 25, 2008, 10:07pm UTC](https://forum.kirupa.com/t/problems-with-movieclip-rotation-within-subclasses/276331 "2008-11-25T22:07:10Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![2dsquid](https://avatars.discourse-cdn.com/v4/letter/2/4bbf92/32.png) [@2dsquid](https://forum.kirupa.com/u/2dsquid)
#### Post date: [November 25, 2008, 10:07pm UTC](https://forum.kirupa.com/t/problems-with-movieclip-rotation-within-subclasses/276331/1 "2008-11-25T22:07:10Z")

</div>

Hi guys, I have been tackling this problem all day and not getting anywhere… Basically I have a turret that should aim at the mouse. Simple right? Apparently not. Check it out:

```auto

//This function (should) rotate the gun to aim at a particular point
//Called from the enterframe event
public function aim(e:Event) {
    var dx:Number = mouseX - this.x;
    var dy:Number = (mouseY - this.y) * -1;
    var newAngle:Number = Math.atan2(dy,dx)*180/Math.PI;
    if (dx < 0) newAngle += 180;
    if (dx >= 0 && dy < 0) newAngle += 360;
            
    this.rotation = (newAngle * -1) + 90;
    trace(rotation);
}

```

Demo: [http://bloonlabs.com/cobraCannon/Snake\_alpha2.htm](http://bloonlabs.com/cobraCannon/Snake_alpha2.htm)

If you have any ideas on what I did wrong please let me know.

The above function is within a Gun class which is a movieclip that has been added as a child to the stage.

Thanks!
