Posted By

Activetuts on 01/13/11


Tagged


Versions (?)

Who likes this?

14 people have marked this snippet as a favorite

chus
elbjoern
EderChrono
shoffa
toxin20
jasongrandelli
leadingmannigel
ichnoweb
kure69
AndrewPotter
JaaQ
elderhsouza
scottwatkins
flashdeveloper


Find the Angle Between Two Points


 / Published in: ActionScript 3
 

URL: http://enva.to/e4ig6z

This is another common snippet used by game developers for finding the angle between two points on a plane. This function has four parameters, the first pair is the x and y values of your first point and the second pair the x and y values of your second point. It's important to note this function returns the angle in radians NOT degrees.

  1. function getAngle (x1:Number, y1:Number, x2:Number, y2:Number):Number
  2. {
  3. var dx:Number = x2 - x1;
  4. var dy:Number = y2 - y1;
  5. return Math.atan2(dy,dx);
  6. }

Report this snippet  

You need to login to post a comment.