Sign in to follow this  
grasshopa55

Fighting Game Hit Detection - Life

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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 );
}
}

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this