2
\$\begingroup\$

My game uses physics (Box2D in particular). Just about every object in the game can be destroyed, and the primary method of combat is by slamming objects into one another at high speed. It makes sense that I would use the object's velocity and mass in order to determine damage. My question is...how?

As I see it, my two main options for computing damage are as a function of the object's momentum (p = m*v) or its kinetic energy (KE = .5 * m * (v^2)), both translational and rotational.

The following statements hold true of my game:

  • Objects can also collide with walls, which are indestructible (but not necessarily immovable). The object takes damage, but the wall does not.
  • Objects can move freely, and certain kinds of objects can also rotate.
  • This is a top-down game, so gravity is not a concern.
  • Different objects can vary in size, mass, and shape, often considerably.

Given this...

  • Which should I use to determine the damage an object takes upon collision; its momentum or its kinetic energy?
  • What other physical properties should I consider when doling out collision damage, and how?
  • How should I handle the (quite possibly substantial) differences in these quantities between the two colliding objects?
\$\endgroup\$
1
  • 2
    \$\begingroup\$ What's more important -- which algorithm is "right", or which one plays better? If the latter, it seems like it would be trivial to try both. \$\endgroup\$ – Kevin Krumwiede Jan 4 '16 at 8:44
2
\$\begingroup\$

If you want realism, you should consider that on impact kinetic energy can be transformed in a few different ways. It can cause movement, or be converted into other forms of energy, usually by deforming/damaging the objects involved in the impact. Assuming that when two objects collide they bounce away in some manner, you could base damage on the loss of kinetic energy ie. the energy converted to other forms during the impact. (delta_KE = KE_initial- KE_final) This will not work if your collisions are totally elastic.Momentum is still conserved by inelastic collisions (the typical example being two cars crashing together).

This also causes damage to adapt to bounciness. Colliding with a large rubber object will make you bounce back faster than colliding with a metal object of equal mass. More velocity is converted to damage by the impact with the metal object, which makes sense. Although you did not mention a 'bounciness' property for your objects, this is a stand-in for whatever method/values you are using to determine how fast objects move away from each other.

Another effect of a kinetic energy based approach is that it causes speed to be more important than mass, so a bullet does more damage than bumping into a very heavy, very slow moving object. (This would happen for both KE and delta_KE approaches) Momentum based approaches give equal importance to each object. (Correct me if I'm wrong but) From the tone of your question I think you want to encourage players to try to throw things as fast as possible more than they try to find the heaviest items. Rewarding the game-play you want with better damage will help with that.

\$\endgroup\$
3
\$\begingroup\$

You could use both, depending on case and need. Both are valid and both occur together.

The difference in your case is apparently how you define loss of energy, ie. what is more convenient and accurate.

In case of momentum, we have P=mv, and you can only work with v; in practice only with elastic collisions. Here is the classic example of (indestructable) momentum, in an (almost) closed system: Elastic collision

How would one manage energy loss there? Maybe by saying "next speed = 99 % of previous", or something. The mass remains, so only v is left. For truly elastic collisions, you could ofc estimate v1 (incoming speed) and v2 (what is left after collision - maybe hard code a max/min percent?), calculate the difference and transfer what was lost as momentum to the target object, using it's mass - you get a velocity. The target will then move nicely. One must ofc always do the calculation in both directions.

But as soon as there are more "daily" objects, and one aims for realism, i think the kinetic energy E=0.5mv^2 comes in. Then it's a question of defining how much the parties absorb when being hit, and then using the rest for calculating speed changes for the objects. Here is (almost) fully plastic collision.

It might be easier to work with the "how much absorbs" when using kinetic energy. Maybe use percentages of the full energy? Then you may have a better chance to get it look right by modeling, by using trial and error.

  1. Calculate how much energy the whole system has at collision (say the two cars). That is 2 * 0.5mv^2.
  2. Calculate how much of that A absorbs, how much B absorbs (use strength, health settings etc). Say A absorbs 20 % of the full energy, B absorbs 30 %. Remains 50 %.
  3. Both "get" equally much of the remaining energy. So add 50 % of it (opposite direction!) to A:s existing energy, 50 % to B:s, then resolve a new (lower) velocities for both. If for example a car collides with a heavy truck, then remaing 50 % for the car will be so big that it may exceed it's original energy, and hence it changes direction of movement. The trucks remaining 50 % is small compared to it's original energy, so it only slows down.

The absorbing figures will likely be close to 100 % in total, as anything else will cause a bit of bounciness. I think you will have to spread out (repeat) the calculation over multiple frames, as these should be higher grade equations in reality. If the collision isn't fully elastic, the objects absorb for a longer duration of time.

Finally, you get a more realistic damage model when using kinetic energy, because apparently absorbing energy causes damage? Will be more accurate than using momentum.

\$\endgroup\$
3
  • 1
    \$\begingroup\$ Damn. 1 year old question :-). This is annoying in SO. \$\endgroup\$ – Stormwind Mar 23 '17 at 0:54
  • \$\begingroup\$ have an upvote! (was a good read for me) \$\endgroup\$ – lozzajp Mar 23 '17 at 11:50
  • 1
    \$\begingroup\$ Hey, I still get notifications for it. Thank you for the answer! \$\endgroup\$ – JesseTG Mar 24 '17 at 15:45

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.