I work in Unity3D 5.3.4 on Windows 10.

There is a complex body consisting of several separate Rigidbody2D and CircleCollider2D , which are connected to each other via a SpringJoint2D . The task is to determine with what force the body hit the surface when it falls, so that when it hits more than a certain value, it reduces the strength and, if it drops to 0, start the object destruction procedure. What did for this. Added on each element an object fixing a collision:

 void OnCollisionEnter2D(Collision2D collision) { float power = collision.relativeVelocity.magnitude; if (power >= dangerPower) { state.SetPower(power); } } 

at each step, the impact force in a collision is determined and the maximum value is stored in the state object for analysis.

Conducted tests with one Rigidbody2D+Collider2D (ball). When falling from one height, the value is constant. When I drop my body, the force of the blow there is different every time. I suspect that when the spring strikes from connected objects, they force the object to lose some of the energy and the speed after the impact due to this decreases.

If you complicate the tests and make a fall with the initial acceleration to the side and blows with a rebound from the side surface, then after falling on the floor, the value deviates even more and already even the ball has no stability in the obtained value.

In the ducks how is it stable to determine how much damage after a fall? Maybe someone has experience in solving such problems, or at least an idea how to make a calculation.

    2 answers 2

    And why not do it just by multiplying the speed of the falling object at the moment of impact on the mass of the falling object?

    You will also need to measure the speed at a very specific coordinate (depending on the side of impact)

    In fact there will be a stable value as a result.

    • The difficulty is that every time you strike, the speed is different, apparently due to the fact that at the moment of impact, in addition to gravity, the spring force also acts on the body. - KingPeas

    As a result, the solution was chosen as follows: For an object, the calculation of the speed at which the body collides with the surface was performed in several steps. While the body falls before the strike, we follow the speed. When a contact to the surface is recorded for several frames, we determine how much speed has gone out relative to the speed in flight. After several iterations, or when contact with the surface is interrupted, we consider how much speed was canceled, and from it we are already calculating the impact force.