Sep 21, 2012 at 3:18 PM
Edited Sep 22, 2012 at 1:12 PM
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
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 ;)