Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice
  2. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  3. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Physics2D - The value of Contact2D.normalImpulse is wrong [2018.4.11f1]

Discussion in '2D Experimental Preview' started by aegis123321, Oct 15, 2019.

  1. aegis123321


    Jul 5, 2015
    There is a falling box hit a another box which stay on ground(box).
    See figure 1:
    Here are properties of these boxes:

    Top Box:
    Name: Impacting
    Body Type: Dynamic
    Mass: 10
    The rests are default.​
    Center Box:
    Name: Impacted
    Body Type: Dynamic
    Mass: 1
    Collision Detection: Continuous
    Interpolate: Interpolate
    Constraints: Freeze Rotation Z​
    Bottom Box(the ground):
    Name: Ground
    Body Type: Static
    The rests are default.​

    And I write a script to get the impulse value when Center Box is hit.
    Code (CSharp):
    1.         private void OnCollisionEnter2D(Collision2D collision) {
    2.             if (collision.rigidbody == null) { return; }
    3.             m_IsHitted = true;
    4.             if (!showConsole) { return; }
    5.             Debug.LogFormat("[{0}]OnCollisionEnter2D {1}", s_FixedUpdatedCount,;
    6.             foreach (var contact in collision.contacts) {
    7.                 Debug.LogFormat("Normal Impulse: {0}, Hit Point: {1}", contact.normal * contact.normalImpulse, contact.point);
    8.             }
    9.             Debug.Log("==============");
    11.         }
    12.         private void OnCollisionStay2D(Collision2D collision) {
    13.             if (collision.rigidbody == null) { return; }
    14.             if (!showConsole) { return; }
    15.             Debug.LogFormat("[{0}]OnCollisionStay2D {1}", s_FixedUpdatedCount,;
    16.             foreach (var contact in collision.contacts) {
    17.                 Debug.LogFormat("Normal Impulse: {0}, Hit Point: {1}", contact.normal * contact.normalImpulse, contact.point);
    18.             }
    19.             Debug.Log("==============");
    20.         }
    and then the result is:

    Center Box get (0.0, 109.7f) impulse from Bottom Box(ground)
    and get (-70.5f) impulse from Top Box.
    It's weird. The total of them must be close to (0, 0) because the original and terminal velocity of the Center Box are close to (0, 0).

    and here is the value of inspector:

    and I found that if both of Top Box and Center Box are Freeze Rotation or Don't Freeze Rotation then the result will be right.

    Attached Files: