12:50 PM 12:50 PM12:50 PM
 

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: www.benoitfreslon.com_Throw_bullets_to_mouse_direction.zip

06:17 PM 06:17 PM06:17 PM
 

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

Download the source code here: [www.thisisgameplay.com]_Orient_object_to_mouse_cursor.fla