Legacy Documentation: Version 2017.2 (Go to current version)
LanguageEnglish
  • C#
  • JS

Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

ContactFilter2D

struct in UnityEngine

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Description

A set of parameters for filtering contact results.

Use a contact filter to precisely control which contact results get returned. This removes the need to filter the results later, is faster, and more convenient.

For more information on using ContactFilter2D with casting, see: Physics2D.CircleCast, Physics2D.BoxCast, Physics2D.CapsuleCast, Physics2D.Linecast, Physics2D.Raycast, Collider2D.Raycast, Collider2D.Cast and Rigidbody2D.Cast.

For more information on using ContactFilter2D with overlapping areas, see: Physics2D.OverlapPoint, Physics2D.OverlapCircle, Physics2D.OverlapBox, Physics2D.OverlapArea, Physics2D.OverlapCapsule, Physics2D.OverlapCollider, Rigidbody2D.OverlapCollider and Collider2D.OverlapCollider.

For more information on using ContactFilter2D with contacts, see: Physics2D.GetContacts, Collider2D.GetContacts, Rigidbody2D.GetContacts, Physics2D.IsTouching, Rigidbody2D.IsTouching and Collider2D.IsTouching.

Properties

isFilteringGiven the current state of the contact filter, determine whether it would filter anything.
layerMaskSets the contact filter to filter the results that only include Collider2D on the layers defined by the layer mask.
maxDepthSets the contact filter to filter the results to only include Collider2D with a Z coordinate (depth) less than this value.
maxNormalAngleSets the contact filter to filter the results to only include contacts with collision normal angles that are less than this angle.
minDepthSets the contact filter to filter the results to only include Collider2D with a Z coordinate (depth) greater than this value.
minNormalAngleSets the contact filter to filter the results to only include contacts with collision normal angles that are greater than this angle.
useDepthSets the contact filter to filter the results by depth using minDepth and maxDepth.
useLayerMaskSets the contact filter to filter results by layer mask.
useNormalAngleSets the contact filter to filter the results by the collision's normal angle using minNormalAngle and maxNormalAngle.
useOutsideDepthSets the contact filter to filter within the minDepth and maxDepth range, or outside that range.
useOutsideNormalAngleSets the contact filter to filter within the minNormalAngle and maxNormalAngle range, or outside that range.
useTriggersSets to filter contact results based on trigger collider involvement.

Public Methods

ClearDepthTurns off depth filtering by setting useDepth to false. The associated values of minDepth and maxDepth are not changed.
ClearLayerMaskTurns off layer mask filtering by setting useLayerMask to false. The associated value of layerMask is not changed.
ClearNormalAngleTurns off normal angle filtering by setting useNormalAngle to false. The associated values of minNormalAngle and maxNormalAngle are not changed.
IsFilteringDepthChecks if the Transform for obj is within the depth range to be filtered.
IsFilteringLayerMaskChecks if the GameObject.layer for obj is included in the layerMask to be filtered.
IsFilteringNormalAngleChecks if the angle of normal is within the normal angle range to be filtered.
IsFilteringTriggerChecks if the collider is a trigger and should be filtered by the useTriggers to be filtered.
NoFilterSets the contact filter to not filter any ContactPoint2D.
SetDepthSets the minDepth and maxDepth filter properties and turns on depth filtering by setting useDepth to true.
SetLayerMaskSets the layerMask filter property using the layerMask parameter provided and also enables layer mask filtering by setting useLayerMask to true.
SetNormalAngleSets the minNormalAngle and maxNormalAngle filter properties and turns on normal angle filtering by setting useNormalAngle to true.

Did you find this page useful? Please give it a rating: