Translate

Monday, May 13, 2013

Code Snippet to find angle between two points

This snippet will be very useful for 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.

function getAngle (x1:Number, y1:Number, x2:Number, y2:Number):Number 
{

var dx:Number = x2 - x1;
var dy:Number = y2 - y1;

return Math.atan2(dy,dx);
}

No comments:

Post a Comment