1 vector explosion_calcpush_nomultiplier(vector explosion_v, vector target_v)
3 // solution of the equations:
4 // v' = v + alpha vp // central hit
5 // m*v' + mp*vp' = m*v + mp*vp // conservation of momentum
6 // m*v'^2 + mp*vp'^2 = m*v^2 + mp*vp^2 // conservation of energy (ELASTIC hit)
7 // -> alpha = 0 // case 1: did not hit
8 // -> alpha = 2*mp*(vp^2 - vp.v) / ((m+mp) * vp^2) // case 2: did hit
9 // // non-elastic hits are somewhere between these two
12 alpha = explosion_v * (explosion_v - target_v);
15 // target is too fast to be hittable by this
18 alpha /= (explosion_v * explosion_v);
19 // now alpha is a multiplier
20 // we know we can divide by this, or above alpha would be == 0
27 vector explosion_calcpush(vector explosion_v, float explosion_m, vector target_v, float target_m, float elasticity)
29 // solution of the equations:
30 // v' = v + alpha vp // central hit
31 // m*v' + mp*vp' = m*v + mp*vp // conservation of momentum
32 // m*v'^2 + mp*vp'^2 = m*v^2 + mp*vp^2 // conservation of energy (ELASTIC hit)
33 // -> alpha = 0 // case 1: did not hit
34 // -> alpha = 2*mp*(vp^2 - vp.v) / ((m+mp) * vp^2) // case 2: did hit
35 // // non-elastic hits are somewhere between these two
37 // this would be physically correct, but we don't do that
38 return explosion_calcpush_nomultiplier(explosion_v, target_v,
42 target_m + explosion_m
48 // simplified formula, tuned so that if the target has velocity 0, we get exactly the original force
49 vector damage_explosion_calcpush(vector explosion_f, vector target_v, float speedfactor)
53 return explosion_calcpush_nomultiplier(explosion_f * speedfactor, target_v) * (1.0 / speedfactor);