FlxMath
offers several helper functions check the distance between an object and a {$ flixel.math.FlxPoint %}, the mouse, a touch, or another object.
Use distanceToMouse
, distanceToPoint
, distanceToTouch
, and distanceBetween
to get the distance in pixels between your object and the relevant item.
// get the distance between your target and a FlxPoint
distance = FlxVelocity.distanceToPoint(target, point);
Note: Use the related `isDistanceTo*Within` functions if you just want to check if the distance is within a specific value. These functions avoid the expensive `Math.sqrt` call that is used in the other functions.