0
\$\begingroup\$

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.

\$\endgroup\$
2
  • \$\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\$ Commented Feb 2, 2013 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
    Commented Feb 2, 2013 at 19:06

1 Answer 1

1
\$\begingroup\$

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?

\$\endgroup\$
1
  • \$\begingroup\$ Damn. Not sure how I managed to overlook that. \$\endgroup\$
    – David
    Commented Feb 2, 2013 at 16:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .