Make cannon aim on mouse click?

Post about the Flash World Construction Kit and the Alchemy port of Box2D.
Posts: 17
Joined: Thu Mar 07, 2013 4:00 pm

Make cannon aim on mouse click?

Postby Farjuan » Thu May 16, 2013 1:42 pm

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;

Posts: 172
Joined: Thu Mar 01, 2012 9:31 am

Re: Make cannon aim on mouse click?

Postby IstvanOrosi » Tue Jul 02, 2013 4:31 pm

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.

Return to “WCK”

Who is online

Users browsing this forum: No registered users and 1 guest