CanContact(Collider2D)
This method determines if both Colliders can ever come into contact.
Read time 1 minuteLast updated 10 days ago
Definition
- Type: Method
- Namespace: UnityEngine
- Assembly: UnityEngine.Physics2DModule
public bool CanContact(Collider2D collider)
Parameters
The other Collider that is to be checked to see if it can contact the current Collider.
Returns
Type | Description |
|---|---|
| bool | Returns |
Remarks
Determining if Colliders can come into contact involves multiple checks including:
-
Each Collider2D must be active and enabled. See _isActiveAndEnabled.
-
Each Collider2D must be on a GameObject that is in the same PhysicsScene2D. By default, this is true but see PhysicsSceneExtensions2D.GetPhysicsScene2D and LocalPhysicsMode.Physics2D.
-
Each Collider2D that is attached to a Rigidbody2D must have a compatible _bodyType. For instance RigidbodyType2D.Static cannot contact another RigidbodyType2D.Static. Without a Rigidbody2D, the Collider2D is implicitly Static. Kinematic vs Kinematic/Static will only contact if _useFullKinematicContacts is enabled.
-
The Collider2D will not contact if they are specified using Physics2D.IgnoreCollision.
-
The Collider2D will not contact if their layer collision (in the Layer Collision Matrix) is set to not contact unless overriden using the Rigidbody2D and Collider2D layer overrides.