How I properly use Collision.GetContacts()?
Docs say don't use Collision.contacts, to use .GetContacts, but doesn't provide an example. The stuff I found in the forums that uses .GetContacts still pulls from Collision contacts via foreach.
How I properly use Collision.GetContacts()?
https://docs.unity3d.com/ScriptReference/Collision-contacts.html
Answer by Relan42 · May 15 at 08:34 PM
You basically have to make an array to store the contacts and to get the contacts you need to use OnCollisionStay or OnCollisionStay. Like this.
private ContactPoint2D[] contacts;
private void OnCollisionStay2D(Collision2D collision)
{
contacts = collision.contacts;
}
Your answer
Follow this Question
Related Questions
How do I prevent Circle Collider 2D from rotating when gravity is in effect? 1 Answer
Moving cubes automatically on the y-axis 0 Answers
It lags when it collides. Help? :( 0 Answers
Problem with the position in OverlapSphere 2 Answers
Is there a way i can have my object be a trigger but can interact with a other objects 1 Answer