Collision Force / Damage

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

Collision Force / Damage

Postby Spek » Tue Apr 21, 2009 3:37 pm

So, 2 objects collide. Or maybe I just drive my car into a wall. Anyway, I need to do some damage/health reduction. But how to calculate it? I guess damage would depend on:
- Velocity of both objects
- Velocity crossing directions. Car head-on-head / hit 'm in the back / barely scrape each other
- Mass/hardness of both objects. Car versus bird, car versus concrete wall, etc.
- ...?

I would like to calculate the damage for objectA and objectB in the Newton Collision Start callBack, but I'm not sure how to calculate it.

Greetings,
Rick
Spek
 
Posts: 66
Joined: Sat Oct 04, 2008 8:54 am

Re: Collision Force / Damage

Postby Aphex » Tue Apr 21, 2009 5:10 pm

I use this which gives good results:

Code: Select all
   const dFloat kInfiniteMass = 50000.0;
   dFloat body1Mass = BodyMass(body1);
   if (body1Mass == NPhysEng::KInfiniteMass)
      body1Mass = kInfiniteMass;
   dFloat body2Mass = BodyMass(body2);
   if (body2Mass == NPhysEng::KInfiniteMass)
      body2Mass = kInfiniteMass;
   const dFloat invMassSum = 1.0/body1Mass + 1.0/body2Mass;
   const dFloat momentum = collisionData.mNormalSpeed / invMassSum;
   dFloat collisionEnergy = momentum * gPhysEngCollisionEnergyScale;


I suppose you could factor in some restitution coefficients if required (re: bird vs car etc)
Aphex
 
Posts: 144
Joined: Fri Jun 18, 2004 6:08 am
Location: UK

Re: Collision Force / Damage

Postby Spek » Thu Apr 23, 2009 2:57 am

Thanks! It works, although I have to balance a bit with static/dynamic objects. Impacts on the floor are much harder now than with another object. But that's a matter of tuning.

One of the things I want is playing the proper sounds. Soft impacts = no sound, medium impacts = medium sound, hard impact = hard sound. That works now by looking at the energy. But I also like to have 'scraping' or rolling sounds. If an object scrapes, this looped sound should be played, including some particle effects. How to determine that? I saw I can also get the tangentSpeed, maybe that would help?

Greetings,
Rick
Spek
 
Posts: 66
Joined: Sat Oct 04, 2008 8:54 am

Re: Collision Force / Damage

Postby Aphex » Thu Apr 23, 2009 8:56 am

Get the tangent info in the collision callbacks using NewtonMaterialGetContactTangentSpeed & NewtonMaterialGetContactTangentDirections. I just average them out with:

Code: Select all
   tangent = (tangent0*tangentSpeed0 + tangent1*tangentSpeed1);


Also note to do effects you need to get a *consistent* normal from the collision data, which I derived by making a few observations in-game, leading to:

Code: Select all
   (normal * SGN(normalSpeed)) is in direction of (body1 -> body0)


(Maybe someone/Julio can verify the correctness of this?)
Aphex
 
Posts: 144
Joined: Fri Jun 18, 2004 6:08 am
Location: UK


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 5 guests

cron