Make cannon aim on mouse click?

Hello, I am trying to make a canon aim at the point of a mouse click, I cant seem to get it working, ive tried this

Code: Select all

private function mouseDown(e:MouseEvent):void
      {
         this.rotation = Math.atan2(e.localY - this.y , e.localX - this.x) * 180 / Math.PI;
Are you sure the function is being called?

If yes, also check if the angle value is what you would expect. Try setting values manually.

Another thing, are you trying to set the rotation of a dynamic body? That shouldn't work but there are ways to "force" the new rotation.

Original thread: https://box2d.org/forum/viewtopic.php?t=9309