Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

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

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

  1. aegis123321

    aegis123321

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

    Top Box:
    Name: Impacting
    Rigidbody2D:
    Body Type: Dynamic
    Mass: 10
    The rests are default.​
    Center Box:
    Name: Impacted
    Rigidbody2D:
    Body Type: Dynamic
    Mass: 1
    Collision Detection: Continuous
    Interpolate: Interpolate
    Constraints: Freeze Rotation Z​
    Bottom Box(the ground):
    Name: Ground
    Rigidbody2D:
    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, collision.collider.name);
    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("==============");
    10.  
    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, collision.collider.name);
    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:

    Console.png
    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:
    inspector_collider_contacts.png
    same.

    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: