Search Unity

Contact Pairs Mode

Discussion in 'Physics' started by whitexroft, Feb 25, 2021.

  1. whitexroft

    whitexroft

    Joined:
    Oct 22, 2012
    Posts:
    48
    So I have my main character that is based on a non-kinematic discrete rigidbody with a capsule collider, and characters logic feeds movement/gravity into rigidbody's velocity, and it has been running perfect, aside for situations when nothing is feeding the velocity, thus the rigidbody can get an errorous movement and fly away.

    I've then noticed that Unity has Contact Pairs generation mode, which makes kinematics receive OnCollision events, and I am trying make the character entirely kinematic based, by moving transoform.position instead of setting velocity.

    I've enabled All Contacts Pairs, and added OnCollisionEnter and OnCollisionStay method for the character that resolves overlaps, but it seems that some collisions are being ignored. All my geometry is non-convex mesh colliders made of probuilder, and when character is non-kinematic, everything always resolves perfectly.

    Are there conditions under which a kinematic body would not receive a OnCollision event just like a non-kinematic, even though "Enable All Contact Pairs" is selected?

    upload_2021-2-25_18-8-40.png
     
    Last edited: Feb 25, 2021
  2. whitexroft

    whitexroft

    Joined:
    Oct 22, 2012
    Posts:
    48
    And example of a collider that the character may or may not ignore
    Arrow means jumping into

    upload_2021-2-25_18-14-40.png
     
  3. AlTheSlacker

    AlTheSlacker

    Joined:
    Jun 12, 2017
    Posts:
    326
    You say you have a kinematic rigidbody that you are moving with transform.position, but you should be using Rigidbody.MovePosition. If you move the transform you are teleporting the body and collisions may not be detected.
     
    Edy likes this.
  4. whitexroft

    whitexroft

    Joined:
    Oct 22, 2012
    Posts:
    48
    It's because I was certain that as long as transform.position is set in FixedUpdate, there wouldnt be any difference between that and calling MovePosition, or rigidbody.position.

    However, using rigidbody.position takes me into transoform-rigidbody sync hell, apperently. The movement becomes either execution order or "Auto Sync Transforms" flag dependant. F.x calling a random raycast prior or after movement would break/fix movement, because it is causing rigidbody transform synchronization.

    So I am looking at like 10 places in the character snapping code, that worked fine before, but now, if I for example solve my collision in OnCollisionStay and move the character (by both transform and rigidbody), or physically snapp the character to a line I need, I'd get a frame skip in his movement, where the character would have a circumstantial lower speed.

    As much I am capable to test with all of this, the collisions seem to be better. It does seem like using rigidbody.position is a requirement for properly getting OnCollision events. Can't say that yet for sure though, I don't know If it is possible to fix the issues that came up. A lot easier is to roll back to non-kinematic rigidbody with constant position fixture.
     
  5. whitexroft

    whitexroft

    Joined:
    Oct 22, 2012
    Posts:
    48