Flixel Forums

development => help => Topic started by: PRIZZA on Sun, Apr 27, 2014

Title: Dynamic enemy attack hitbox?
Post by: PRIZZA on Sun, Apr 27, 2014
Hello,

What's the best way to have an enemies attack collide with the player based on the state of the enemy? For example, I'd like my enemy to have a small "hitbox" when standing still, but when they are attacking I'd like to widen it a bit so it will overlap more with the player.

Imagine an enemy that just idles with his arms at his side, but when moving he swings a sword up and down.The flixel power tools extension I'm using is great for pixel-perfect collision checks but resizing the hitbox is a bit tricky.

I have an enemy that attacks in the manner described, but the problem is if I have a new hitbox appear for an attack it will immediately hit the player, which doesn't coincide with the frame data of the swinging sword. If the check it done with the enemies hitbox, it will perform a pixel-perfect check and only hit the player when the sword is visually overlapping the player.

Does anyone have any solution for this sort of thing? Thank you!
Title: Re: Dynamic enemy attack hitbox?
Post by: VanDiest on Wed, Apr 30, 2014
you could create an FlxSprite that is invisible and have it follow the enemy. then you could check the collision with that invisible hitbox whenever the enemy state is "attack" or whatever
Title: Re: Dynamic enemy attack hitbox?
Post by: PRIZZA on Thu, May 8, 2014
you could create an FlxSprite that is invisible and have it follow the enemy. then you could check the collision with that invisible hitbox whenever the enemy state is "attack" or whatever

Thanks VanDiest, you gave me a great idea. My solution was very similar to your suggestion.