Basically, my game has the player's attack hitbox change based on the attack being performed. I tried to make a simple collision test that takes an enemy's coordinates and have it check to see if it's within the range of the player. I don't want to resort to using Sprites and use hitTest() since efficiency is an issue. Anyway, the problem lies in the fact that the function below always returns true (even when the player is nowhere near the enemy).

private function quickHitTest(boxLeft:int, boxRight:int, boxTop:int, boxBottom:int, rangeWidth:int, rangeHeight:int):Boolean

return ((boxLeft > (300 - (rangeWidth/2)) && (boxBottom > (450 + (rangeHeight / 2)) || boxTop < (450 - (rangeHeight / 2)))) || (boxRight < (300 + (rangeWidth/2)) && (boxBottom > (450 + (rangeHeight / 2)) || boxTop < (450 - (rangeHeight / 2)))));

I having difficulties finding the source of the problem. All help is appreciated.

  • \$\begingroup\$ Why don't you use flash.geom.Rectangle ? There are methods containsPoint(Point p):Boolean and intersects(Rectangle r):Boolean - see help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/… \$\endgroup\$ – Ivan Kuckir Feb 2 '13 at 19:03
  • \$\begingroup\$ @IvanKuckir Didn't know they existed (haven't exactly played around with flash.geom.Rectangle). I'll keep them in mind for future reference since I'm working on minimizing operations. \$\endgroup\$ – David Feb 2 '13 at 19:06

Why make it so complicated? If you have the coordinates of both the player and the enemy you can just calculate the distance and see if it falls within the range. Or am i misunderstanding something?

  • \$\begingroup\$ Damn. Not sure how I managed to overlook that. \$\endgroup\$ – David Feb 2 '13 at 16:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.