Fighting Game Hit Detection - Life

Started by
8 comments, last by leiavoia 19 years, 5 months ago
I'm having a small problem with the fighting game I am working on. The Hit Detection algorithm I am using works wonderfully, so I'm at the point where I need to deduct the appropriate amount of life-points from the non-blocking opponent. The pseudo code for this is below

if( CheckCollision() )
{
   PlayerBeingHit.life = PlayerBeingHit.life - damage;
}
Seems pretty straight-forward, except this code is executed every frame. Since the frame of animation is on screen for a specific amount of time, this gets fired as long as the frame of animation remains on the screen. This varies depending on the current frame-rate of the application. So, my dilemma. What can I do to prevent the above code from firing after the damage has initially been removed?
-----------------------------kevin@mayday-anime.comhttp://www.mayday-anime.com
Advertisement
You may put in a timer that dictates how long until damage can be received again. But make the timer small enough that consecutive blows can be achieved. Either that or you could have a flag indicating that the player was hit on the last frame and to not give damage this frame.

The latter would indicate that only damage is taken on the first frame they collide and the flag would be set to false when they aren't colliding anymore.

I haven't done this myself so I'm really just rambling ideas off the top of my head.


EDIT: on second thought the timer wouldn't be very realistic with different machines. If I was doing this myself I would try the flag idea out.
split your checks to per character move. if collision happens in a move cycle stop checking for collision until characters next move.
like Themonkster said:

when player 1 throws a punch, have that "move" come with a bool flag. If you hit someone, raise the flag now your code looks more like this

if ( Collision() ) {   if ( !p1.AlreadyDealtDamageThisMove() ) {      p2.HitMe( damage );      }   }
Thanks guys. I'm going to try adding a "wasHit" flag to my player object and see how that works out.
-----------------------------kevin@mayday-anime.comhttp://www.mayday-anime.com
not quite: add a dealt_damage flag to the hitting player's variables. That way damage is only given once per move and can be reset when the move ends.
I believe washit flag isnt as good as reducing small amount of hp every frame. If you have a look at all of the fighting games,the hp point is gradually reduced when a hit collision occurs. washit flag will create a effect which one player receives a punch and all of a sudden the hp bar reduces a large chunk in just one frame and make the game look un-natural.
Certain games use the "big block o' life" trick while others still calculate the total amount of damage and animate the life bar to show gradual loss of life. I've decided to go the big block of life route for now, just to get the area working.
-----------------------------kevin@mayday-anime.comhttp://www.mayday-anime.com
The "Damage Dealt" concept worked great. Thanks for all your help.
-----------------------------kevin@mayday-anime.comhttp://www.mayday-anime.com
Quote:Original post by jimywang
I believe washit flag isnt as good as reducing small amount of hp every frame. If you have a look at all of the fighting games,the hp point is gradually reduced when a hit collision occurs. washit flag will create a effect which one player receives a punch and all of a sudden the hp bar reduces a large chunk in just one frame and make the game look un-natural.


That is an animation trick, nothing to do with the game logic. Subtracting a bit on each frame would be horendously error prone, if not totally unreliable.

This topic is closed to new replies.

Advertisement