If I have objects that collide how do I calculate the force of the impact? Obviously if they are going in roughly the same direction at roughly the same speed the impact is minimal, but if they hit head on the impact is large. How do I calculate this from the two vectors? Thanks.
Calculate force of impact
BlitzMax Forums/BlitzMax Programming/Calculate force of impact calculate your Speed V in to 2 components Vx and Vy
V1=speed
Q1=angle
Vy1 = sinQ * V
Vx1 = CosQ * V
use the above equation for both of object. you will get Vx1 and Vy1 for First Object , then Vx2, Vy2 for second object
now.
Vx = Vx1- Vx2
Vy = Vy1 - Vy2
direction of resultant vector Q = arctan (y/x), if you want resultant direction. or else. ignore this
now. Vx1 + Vx and Vy2+Vy ( you get the resultant speed after collision, Vx2+Vx and Vy2+Vy ( for second object)
use this as basic dynamic physics knowledge and convert to your program
BTW, how to get your first and second object's speed? here..
how many pixels it moved from first Frame to second Frame that you show on display. that's the speed of your object.
V1=speed
Q1=angle
Vy1 = sinQ * V
Vx1 = CosQ * V
use the above equation for both of object. you will get Vx1 and Vy1 for First Object , then Vx2, Vy2 for second object
now.
Vx = Vx1- Vx2
Vy = Vy1 - Vy2
direction of resultant vector Q = arctan (y/x), if you want resultant direction. or else. ignore this
now. Vx1 + Vx and Vy2+Vy ( you get the resultant speed after collision, Vx2+Vx and Vy2+Vy ( for second object)
use this as basic dynamic physics knowledge and convert to your program
BTW, how to get your first and second object's speed? here..
how many pixels it moved from first Frame to second Frame that you show on display. that's the speed of your object.
Ok, but from that how do I decide how much damage to inflict on objects 1 and 2? I want head-on collisions to do more damage than a glance or a nudge, so where how do I get the force of the impact?
Here's some code directly from my game Ananta that features kinetic energy transformation in 30% elastic circle-to-circle collisions. It means 30% of the kinetic energy in a collision of two masses transform into damage.
(Kinetic energy formula: E = 0.5 * m * v^2)
CollEnergy is the energy in Joules that is will be used to inflict damage to the object, and is dependent of the objects' masses.
Never bothered to actually check if the result is real-world-accurate, but it seems to work and looks good enough for me.
Hope this helps some.
(Kinetic energy formula: E = 0.5 * m * v^2)
' COLLISION RESPONSE Local collNormalAngle:Float = ATan2(obj.GetY() - self.GetY(), obj.GetX() - self.GetX()) ' n = vector connecting the centers of the colliding circles ' find the components of the normalised vector n Local nX:Double = Cos(collNormalAngle) Local nY:Double = Sin(collNormalAngle) ' find the length of the components of movement vectors (dot product) Local a1:Double = self.GetXVel() * nX + self.GetYVel() * nY Local a2:Double = obj.GetXVel() * nX + obj.GetYVel() * nY ' optimisedP = 2(a1 - a2) ' ---------- ' m1 + m2 Local optimisedP:Double = (2.0 * (a1 - a2)) / (self.GetMass() + obj.GetMass()) ' now find out the resultant vectors Local elas:Float = 0.7 ' 30% elastic collision Self.SetXVel(Self.GetXVel() - (optimisedP * elas * obj.GetMass() * nX)) Self.SetYVel(Self.GetYVel() - (optimisedP * elas * obj.GetMass() * nY)) ' find out how much kinetic energy is transformed into damage Local xVelAbsorb:Double = (optimisedP * (1 - elas) * obj.GetMass() * nX) Local yVelAbsorb:Double = (optimisedP * (1 - elas) * obj.GetMass() * nY) Local CollEnergy:Float = 0.5 * Self.GetMass() * xVelAbsorb ^ 2 * yVelAbsorb ^ 2 self.SustainDamage(CollEnergy) ' damage to the other object... xVelAbsorb:Double = (optimisedP * (1 - elas) * Self.GetMass() * nX) yVelAbsorb:Double = (optimisedP * (1 - elas) * Self.GetMass() * nY) CollEnergy:Float = 0.5 * obj.GetMass() * xVelAbsorb ^ 2 * yVelAbsorb ^ 2 obj.SustainDamage(CollEnergy)
CollEnergy is the energy in Joules that is will be used to inflict damage to the object, and is dependent of the objects' masses.
Never bothered to actually check if the result is real-world-accurate, but it seems to work and looks good enough for me.
Hope this helps some.
ya. exactly. as Vilu say, E =0.5 m v^2
if you get, resultant Speed (V)
then Force (F) = m v^2
m = mass of object
on the other hand. you can simply specify, how much is your mass, and get the impact force.
then decide how many percentage of FORCE is transform into damage into your object.
If you want more complicated,
then put density into consideration.
such as more dense object will likely resist the damage and less dense will easy to break. that's is.
if you get, resultant Speed (V)
then Force (F) = m v^2
m = mass of object
on the other hand. you can simply specify, how much is your mass, and get the impact force.
then decide how many percentage of FORCE is transform into damage into your object.
If you want more complicated,
then put density into consideration.
such as more dense object will likely resist the damage and less dense will easy to break. that's is.
Note that you should calculate the normal of the collision and the relative velocity between the objects along the normal. This is done in my code snippet above. If you just simply calculate their relative velocity, you can have "fatal" collision even if the objects only brace each other at a high velocity.
Thanks guys. A big help. :)