Collision Handling

Started by
4 comments, last by THACO 18 years, 3 months ago
Ok, I have basically a 2d fighting game and I can detect collisions between players. Currently I do this via lines there are body lines and then attack lines. The attacking player has a set of lines that corrospond to his attack, and the body lines corrospond to an oppenents body. If an attack line crosses a body line then the attacker hit the opponent. The one problem is what to do after? This is what I am thinking. Give the opponent a vector and damage based on the attack animation(the opponent takes X damage and also moves in the vectors direction for set time). The one pseudo problem is the next frame the animation might still have a collision which I could just say overwrite the old one cuz the animation will be the same attack animation. The problem with this is I want to have more than 2 players and have items/objects. This means I need to be able to have a player get hit by multiple objects at practically the same time, and overwritting the damage and vector means it will only be hurt from the most recent attack not a combo. This leads me to having the attacker have an actual array with flags for other player, if hit then the flag will be switched and each collision it will not add its damage and vector to the hurt player. Once the attack animation has ended it will clear the array. I am only forseeing 4 players, no more than 8 so the array wouldn't be huge. Also the objects / items would probably just clear the array after a set time if need be, but most items/objects will either be one time attacks or have to be used by a player to cause damage. Is this last idea adequate? anything I am not thinking about, any better way? thanks for your input -THACO
Advertisement
Thats quite something you have on your hands, you can consider the following:

The attack only occurs once the LEG is fully extended at which point all the leg lines are checked and the damage dealt to those who crosses them.

Think of it as a siege tank with splash damage, although the bullet travels far it only does the damage once.

If you have a moving wave that does damage it gets more complex, you can consider that each attack has X Damage and that it deals this X Damage to each object in its way as it knocks it however each time X Damage is done reduce this damage by half.
----------------------------

http://djoubert.co.uk
The problem with being fully extended is that means there is one exact frame that it will be fully extended. I do use time slices for updating physics, but the problem can be skipping that collision frame if the computer chugs for a second, 2+ time slices could pass and it would skip the collision frame. Also depending on the need to slow the animation down it might run that frame more than once. (I do not do major interpolation)


-THACO
Here's just a suggestion. I don't know the whole situation without seeing the code so this is a shot in the dark. What if you keep a seperate time variable (timeofkick), a boolean flag for when it goes off (haskicked) and a suggested time of execution variable? (timetokick)

During the objects update cycle check if the current time is greater than or equal to the start of animation plus the suggested time of execution. If it is then set the time variable to the time of the kick and the kick flag to true.

//startofanimation = time animation began//animationduration = time length of animation//currenttime = your method of getting the time (timeGetTime?)if ( currenttime >= startofanimation + timetokick ){      timeofkick = startofanimation + timetokick;      haskicked = true;}//.....//check and calculate kick only once per animation cycleif (haskicked){      //use the timeofkick variable to calculate the location of the leg      //and location of the foreign object to test for collision.      //even though it is processed late it will act as if it was on time.      //I'm not sure how your collision system is setup but you may be      //able to use the timeofkick to determine which player gets over      //powered when two players kick eachother.}//....//change haskicked to false before the start of animation variable gets//reset but after you process the time of the kick.if ( currenttime >= startofanimation + animationduration){      haskicked = false;      startofanimation = currenttime;}


I hope that at least gives you some ideas.
Most of our obstacles would melt away if, instead of cowering before them, we should make up our minds to walk boldly through them.- Orison Swett Marden
Quote:Original post by THACO
The problem with being fully extended is that means there is one exact frame that it will be fully extended. I do use time slices for updating physics, but the problem can be skipping that collision frame if the computer chugs for a second, 2+ time slices could pass and it would skip the collision frame. Also depending on the need to slow the animation down it might run that frame more than once. (I do not do major interpolation)


-THACO


These are minor problems, as the other guy says simple have a variable T where T = 1 is fully extended and T > 1 is the pullback animation.

The If (T+DeltaTime > 1) DoDamage

Also if you want it to be fair and if your Game Mechanics are fairly simple compared to your rendering (and it seems to be) have a seperate thread run it at a specific frame rate.
----------------------------

http://djoubert.co.uk
I did think of the if time is greater than fully extended but no damage was dealt yet, deal it. The one problem with that is I have some "sweeping" attacks, one is sorta like Guile from SF2 his flip kick, its not slow, but its also not instantaneous so there really is no fully extended(I hope this is explaned well enough). I think I will just stick with the array of players already hit and reset that array after the animation is completed. I also have done very limited thread coding, currently only in java (this game is C++) so if I needed to do threads I feel I could but I might as well keep it simple. Thanks for all the ideas and advice, I did like the fully extended idea but it just is a little to limiting.

-THACO

This topic is closed to new replies.

Advertisement