/ Published in: JavaScript
This function will calculate the distance between two provided points. This is useful in game development when calculating paths of motion for sprites. The function expects two points to be provided. A point is defined as an object with an "x" and a "y" property. The result is a numeric value of the distance.
Expand |
Embed | Plain Text
function lineDistance( point1, point2 ) { var xs = 0; var ys = 0; xs = point2.x - point1.x; xs = xs * xs; ys = point2.y - point1.y; ys = ys * ys; return Math.sqrt( xs + ys ); }
You need to login to post a comment.
