0
\$\begingroup\$

I'm very new to game development and have been learning more and more about collision detection and such.

However, I don't exactly understand how to detect that a player has attacked an enemy first or vice versa.

The attack would be a melee attack from one entity onto another.

Any general ideas would help :) thanks!

\$\endgroup\$
  • \$\begingroup\$ Could you give more details about your context? How do you perform the attack? How do you detect the collision? \$\endgroup\$ – Vaillancourt Mar 22 '18 at 0:21
  • \$\begingroup\$ Also I removed the tags you added because it's unclear how your collision detection would be related to sprite and animation. \$\endgroup\$ – Vaillancourt Mar 22 '18 at 0:22
  • \$\begingroup\$ It would be a melee attack, done from one entity to another. As of right now I have only implemented bounding box collision but I am not sure if this is what would be needed for this particular issue. \$\endgroup\$ – CharmingSalamander Mar 22 '18 at 0:26
  • \$\begingroup\$ Do you currently have this issue? \$\endgroup\$ – Vaillancourt Mar 22 '18 at 0:28
  • \$\begingroup\$ @AlexandreVaillancourt I am currently implementing a melee attack to work for a player controlled entity, I was mainly asking for the future when enemy AI entities can also attack the player. My issue with the bounding box collision would be that I am not sure how to find out which entity attacked the other first. \$\endgroup\$ – CharmingSalamander Mar 22 '18 at 0:36
1
\$\begingroup\$

The first thing to check would be if Player is attacking and Enemy is not attacking, it's simple enough, if there is a collision, it's the Player who is attacking.

Now if both are attacking, and if their attack motions take the same time, the one who started the attack first would be the one who "wins", i.e. the one who is tagged as attacking.

And if their attack motions do not take the same time, you could check who's closer to the end, percentage-wise, and tag that entity as the one performing the attack.

That being said, there is nothing preventing you to consider both as attacking if they're in an attack motion.

Another thing to consider: what part of an entity hit what part of the other entity? An axe could be split into two parts: the blade (the part that actually performs the attack) and the rest. If the player's blade is in an attack motion, and it hits an enemy's axe (which is also in an attack motion) on "the rest" part, then the enemy attacked too fast or not fast enough, while the player found a sweet spot: the player is tagged as attacking.

| improve this answer | |
\$\endgroup\$
0
\$\begingroup\$

I pulled my attacks out as their own objects and made my characters attackables. When an attack is active and moving through space, it checks if it has collided with any attackables. When it does, it deals damage.

| improve this answer | |
\$\endgroup\$

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.