Author Topic: Dynamic enemy attack hitbox?  (Read 1491 times)

PRIZZA

  • Member
  • **
  • Posts: 24
  • Karma: +0/-0
    • View Profile
Dynamic enemy attack hitbox?
« 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!
« Last Edit: Thu, May 22, 2014 by PRIZZA »

VanDiest

  • Member
  • **
  • Posts: 21
  • Karma: +0/-0
    • View Profile
Re: Dynamic enemy attack hitbox?
« Reply #1 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

PRIZZA

  • Member
  • **
  • Posts: 24
  • Karma: +0/-0
    • View Profile
Re: Dynamic enemy attack hitbox?
« Reply #2 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.