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:
//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
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!