Skip to main content
GameDev.net gamedev.net
🔒 Locked

Trading Hits

Started by Kimimaru Jun 19, 2013 at 9:51 PM 2 replies 1.4k views
Original Post
Kimimaru
Kimimaru

I'm not sure how many of you are familiar with fighting games, but most of them have this mechanic that players call "trading hits" which occurs when both players' hitboxes intersect each other's hurtboxes at roughly the same time. This causes both players to get hurt. You can see an example at 1:41 in this video:

I want to implement something similar in my game. The problem I have right now is it checks for collisions between players starting with player 1, so if both characters tried hitting each other at the same time, player 2 would get hit first and player 1 would be unharmed because player 1 would have hit player 2 first.

I can fix this by having the hitboxes linger. However, it doesn't look good when someone gets hit right after using an attack that lasts for a good 2-3 seconds, causing another player that got in range of the attack to get hit despite a significant amount of time passing since the initial attacker got hit.

In other words, I need to somehow check for both characters getting hurt at the same time, and at the moment I can't think of a clean-cut way to do it. I suppose I can try and keep track of who hit who with which hitbox (there can be multiple active at one time, Ex. Multi-hit attacks), but that'll be a lot of unnecessary information to store considering I already have it all...

Does anyone have any suggestions for implementing such a mechanic? Thanks in advance!

_paf
_paf

Well, i think a good option is the one you described, you could do all the collision tests between the players, and instead of executing the consequences of any collision immediately after any collision happens, just save the result of whether none, one or both players where hit, and execute whatever action at the end of all collision tests.

Example:

Player 1 punches player 2. When it's time to check for collisions you check player 1 first to check if he hit player 2, and it did. Now instead of immediately making player 2 hit (whatever you do, like changing to "hit" animation, decrease HP, etc), just have some boolean variable hold the result of the test.

Do the same for player 2 (check collision, etc).

At the end of the tests, check the boolean values and see if anyone was hit. If only one of the player was hit, then you do the normal thing when one takes damage, and if both have been hit, then it's the "trading hits" case.

This works equally for multiple hit-boxes, the only difference is that you check all hit-boxes for collisions and save all the results.

Basically delay the actions of collisions until all the tests are completed.

Kimimaru
Kimimaru

All right, I'll see how it ends up working out. Thanks for the help!

Kimimaru
Kimimaru

Sorry for the double post.

This is turning out to be a bit more complex than I thought. There are 4 players max in my game so I have to check collisions for the hitboxes of all of them, which isn't a problem. However, the troubling part is players can pick up weapons which have their own hitboxes, and some characters have projectiles that they can shoot which also have their own hitboxes. Since projectiles and weapons can't trade, I have no reason to store the data. Unfortunately, this means that the damage done by those objects will occur before the normal player collisions.

This also means that if I do carry out the damage by normal player collisions after the damage done by the weapons/projectiles, the player getting hurt will lose much more health than normal because instead of just getting hurt by the weapon, the player will receive damage from the weapon and the player who hit him/her. This will ruin combat since much more damage will be dealt than normal.

Fortunately, I think I may have a solution. If a player hit another player, I can check if any other player hit that player back and make them both take damage if necessary. I don't know how this sounds to you guys but it's the first thing that came to mind. Any other suggestions?

EDIT: I figured it out (but haven't implemented it yet). Collisions for player hitboxes go before all else but would take effect right after projectiles due to trading, so I simply moved the player hitbox collisions after the projectiles. This prevents a player from receiving damage when he/she shouldn't be able to get hurt in the first place. Weapons take place after projectiles and player hitboxes, so they're fine. As long as one type of collision is checked before another type and doesn't take effect after the other check, there will be no problems.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.