This project has moved and is read-only. For the latest updates, please go here.

# Collision force/damage

 Topics: Developer Forum, User Forum Wiki Link: [discussion:396409]
 JohnHolmes Sep 21, 2012 at 4:18 PM Edited Sep 22, 2012 at 2:12 PM Hi All, I'm from Ad Maiora team and would like to talk about a common topic which I haven't found any satisfying answer for: damage/force on collisions. We're working on a Angry-Birds like game (very different from it but similar in mechanics), and I'm trying to figure out the best way to compute the damage that an entity causes to another. Referring to the simplest case of two entities that collide, I devised some methods, each one with pro/cons. I'll be calling P1, P2, P3 and P4 the four biggest problems I ran into.   1-) the simplest: and entity causes a damage on the other equal to its kinetic energy (E=1/2*m*v*v). This can be handled by using the body's delegate OnCollide. It works decently for many scenarios. The biggest problem (P1) of this is that it doesn't consider the other entity's velocity. It might happen, in fact, that the two entities are moving along the same line with very similar velocity, but when they collides, the system computes the damage considering one velocity (entity) at time => big damage even with similar velocities. Moreover, it handles very bad another situation (P2). Imagine an object (A) moving towards the right and another (B) falling on top on it. Obviously the velocity of A shouldn't affect the damage, but it is taken into acount for the A's OnCollide, ending with a unreal damage for B.   2-) when two entities collide, compute V = V1-V2 and use it to retrieve the damage. But this doesn't sort the second problem (P2) of the previuos case. This has another kinda issue (P3): if some entity has a sort of damage multiplier (a float multiplied by the damage), and it happens to be still, the multiplier is it taken into account anyway, since in this case there is a unique velocity for the collision event.   3-)let the collision take place, and after it compute the velocity-delta of each entity (new_vel-prev_vel). This seems capable of handling every problem highlighted before, but it introduces a new one (P4): collision cannot be avoided anymore, since both AfterCollisionEventHandler and PostSolveDelegate are called after the separation/bounce impulses have been applied. I need to be able to avoid collision :) (think about the yellow Angry Birds bird).   4-)use the separation/penetration values provided by Farseer as a measure of the impact force. But I am not able to find them nowhere :/ Where are they ???Unfortunately, maybe this doesn't allow you to ignore a collision (P4).   5-)use the impulse applied to a body to correct its velocity responding to the collision as a measure of the impact force. As before, I can't find it :'(Does this handle P4 ?   ------ What do you suggest ??? Am I missing something trivial ??  Please help because I can't find any "perfect" solution ;) THANKS,bye ! jerrysb Sep 22, 2012 at 10:25 AM Edited Sep 22, 2012 at 10:26 AM Hi, I don't think this is a trivial issue in the general case. I was tackling this problem myself for a more formal simulation (think car crush testing and deformation measurment). The actual physical problem is called "impact loading". I found this explanation useful: http://www.pdhcenter.com/courses/s164/s164content.pdf I think you have found that using deltaV is a viable estimates because basically if you assume mass=1 and deltaTime=1 and applying the impulse-momentum relationship you get the loading force. You can then apply damage similar to how the breakable objects logic works (if above a threshold break the object).  In 3) you have to consider that Box2D callbacks are Begin/EndContact, Pre/PostSolve. Those are global. Farseer has additional mechanism OnContact/OnSeparation, Begin/EndCollision that is fixture-specific. All of those are called in the solver. Probably it's good to choose one system and not mix them. I am not familiar with the yellow bird but you can ignore the contact in the callbacks and even apply your own impulses. 4) The separation values are in Contact specifically the manifold. You get contact points (1 for circle vs anything and 2 for polygon vs polygon). You also get a normal along which the impulses will be applied. In PostSolve you get the impulses applied by the solver. 5) has a caveat. The impulses applied to two bodies are equal and opposite. This means a very heavy body will receive same damage as a small body striking it. Force is a better measurment for "deformation". The Earth deforms while we walk on it but it's negligible because of its mass so I would take mass into consideration before applying damage. Also consider "grazing" hits when the bodies collide on a tangent. It's not an easy problem. I'm very interested in how you solve your problem. Please post when you find a system that works. JohnHolmes Sep 23, 2012 at 9:11 PM Edited Sep 23, 2012 at 9:12 PM Thanks for replying. I took a look at the paper you linked, I found it interesting but out of my scope, which is simply making an AngryBirds physics like game, that is, using simple elastic collisions. Farseer is capable of handling all of this ;) Since my framework is using OnCollide/OnSeparation, and our game is about to be published, I didn't try to use Begin/EndContact and Pre/PostSolve methods because of lack of time. I figured just now that I could use OnSeparation instead of OnCollide (which is prominently what I'm using now) to implemet the solution 2) of my previous post. Maybe I'll try later. But this doesn't handle object with zero restitution, because OnSeparation wont follow a OnCollide. However, I was unable to use the Manifold impulses value because they are always zero ! °_°Do you know why ?If they were avaiable, I could use them for a perfect impact force estimation. Right now I'm doing this, for each entity/body: - compute the collision point velocity with GetLinearVelocityFromWorldPoint - project this velocity onto the normal of the collision point. This "rewards" nice perfectly alligned shots with a high damane, and avoid that stupid shots have the enemy killed. - compute the final damage to apply to itself and the enemy using the kinetic forse from this projected velocity. This method doesn't handle the problem P2 (my prev post) at all, but it's ok anyway because in my kind of game this is a improbable situation.   Finally, I don't think that "impulses applied to two bodies are equal and opposite". It depends for sure on the mass. Correct ?