Search Unity

Using Rigidbody2D.GetContacts for grounded check

Discussion in 'Physics' started by besttof, Nov 29, 2020.

  1. besttof

    besttof

    Joined:
    Jul 17, 2012
    Posts:
    29
    Hello,

    I'm trying to use the contact points from
    Rigidbody2D.GetContacts
    to determine if a rigidbody is grounded. Getting the contacts and the info is all working as expected, but there is a situation that I don't fully understand: when you apply a force to the rigidbody (e.g. a jump force), the frame after applying that force there are still contact points returned.

    The contact points at that point have an opposite relative velocity from the applied impulse (which might sort of make sense, but I'd only expect those on the other body) but most puzzlingly they still have the same separation values even though the rigidbody has moved significantly (well over the Default Contact Offset value). Actually, all values but the relative velocity are equal.

    Assuming the values for those contact points are correct, they can be quite far from the rigidbody's colliders, so I don't want to count those frames as grounded. How do distinguish these contacts from "valid" grounded contacts?

    edit:
    I just noticed that the collider contact gizmos _do_ show correctly as seen in these consecutive frames. I draw a green line from the rigidbody position to the contact point position (and a transparent green arrow for each point's relative velocity), but their positions also don't match...

     
    Last edited: Nov 30, 2020