ActionScript: Throw bullets to mouse direction

After calculating the angle of 2 graphic objects, you can also use this angle to throw a bullet to the object direction with the trigonometry.

How ?

  1. Calculating the angle (in radian) between 2 graphics objects with the Math.atan2 method (cf. Orient object to the mouse cursor).
  2. On click, display a bullet to the “tank” position and add an “enter frame” event on this bullet.
  3. And save the angle between the tank and the mouse cursor on the new  bullet.
  4. Use this angle on the “enter frame” event to calculate the x and y speed with the cosinus and the sinus.

Download source:

ActionScript: Orient an object to the mouse cursor with Flash

How to orient an objet to an other ? Just put those lines and change the instance name myTank.

Download the source code here: []_Orient_object_to_mouse_cursor.fla