Collision force

Oct 16, 2010 at 12:33 PM

Hi,

I'm using the OnCollided callback to respond to collisions. But I wish to know how much force is involved in the collision so I can use it to do damage to the involved entities. OnCollided does not provide this information. Is there another way to obtain it?

Thanks!

Coordinator
Oct 17, 2010 at 5:54 PM

Hi Xcone, You can get a factor to use for damge based on the velocities of the rigid bodies involved in the collection.  There are many ways to get this factor, but a common way is to project the velocities of the involved rigid bodies onto the collision normal.  So, something like this:

float dot0 = Vector3.Dot(shape0.RigidBody.Velocity, normal);

float dot1 = Vector3.Dot(shape1.RigidBody.Velocity, normal);

float damageFactor = (dot0 - dot1) * <some constant>.

The "(dot0 - dot1)" may be "(dot1 - dot0)" but regardless, you may have to check the magnitude and/or sign of the damageFactor to determine if you want to cause damage. Good luck!

Oct 17, 2010 at 8:21 PM

Thanks for your response. 

Shouldn't mass be part of this calculation? Since larger/heavier objects are prone to cause more damage. Or should this be part of <some constant>?

Coordinator
Oct 19, 2010 at 4:22 AM

Mass can be part of the calculation but probably shouldn't be applied until after you have determined that the "relative velocity" is large enough to warrant damage. 

I believe you can also subtract the velocities first, and dot the result to the normal to save some multiplications.

Oct 19, 2010 at 6:06 AM

Aight! I'm starting to get results within the line of expectation now. Thx for putting me on track!

Oct 19, 2010 at 7:59 PM

Hi,

It seems there's still something wrong ..

When calculating the collisionSpeed, the result is sometimes negative and sometimes positive. Is this normal behaviour? Could it be the normal sometimes faces from shape 0 to shape 1, and sometimes the other way around? And if so, what's the proper way to solve it. I could the Abs() the result, but I'd rather fix the cause of this if possible.

Coordinator
Oct 25, 2010 at 3:16 AM

The normal of the collision should "point" at the first shape.  Negative and positive results are expected though.  Have you tried filtering out negative/positive results and see how that affects your damage calcs?  It may be that it signals that damage shouldn't occur