Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


ContactFilter2D

A set of parameters for filtering contact results. Define the angle by referring to their position in world space, where 0 degrees is parallel to the positive x-axis, 90 degrees is parallel to the positive y-axis, 180 degrees is parallel to the negative x-axis, and 270 degrees is parallel to the negative y-axis.
Read time 3 minutesLast updated 4 days ago

Definition

  • Type: Struct
  • Namespace: UnityEngine
  • Assembly: UnityEngine.Physics2DModule
public struct ContactFilter2D

Remarks

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.
If you are using a function that requires a ContactFilter2D, but you don't want to perform any filtering, then use ContactFilter2D.NoFilter.
For more information on using ContactFilter2D with overlapping areas, see: Physics2D.OverlapPoint, Physics2D.OverlapCircle, Physics2D.OverlapBox, Physics2D.OverlapArea, Physics2D.OverlapCapsule, Physics2D.OverlapCollider, OverlapCollider and OverlapCollider.

Fields

Value

Description

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 ContactFilter2D.minDepth and ContactFilter2D.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 ContactFilter2D.minNormalAngle and ContactFilter2D.maxNormalAngle.
useOutsideDepthSets the contact filter to filter within the ContactFilter2D.minDepth and ContactFilter2D.maxDepth range, or outside that range.
useOutsideNormalAngleSets the contact filter to filter within the ContactFilter2D.minNormalAngle and ContactFilter2D.maxNormalAngle range, or outside that range.
useTriggersSets to filter contact results based on trigger collider involvement.

Properties

Property

Description

isFilteringGiven the current state of the contact filter, determine whether it would filter anything.

Methods

Method

Description

ClearDepthTurns off depth filtering by setting ContactFilter2D.useDepth to false. The associated values of ContactFilter2D.minDepth and ContactFilter2D.maxDepth are not changed.
ClearLayerMaskTurns off layer mask filtering by setting ContactFilter2D.useLayerMask to false. The associated value of ContactFilter2D.layerMask is not changed.
ClearNormalAngleTurns off normal angle filtering by setting ContactFilter2D.useNormalAngle to false. The associated values of ContactFilter2D.minNormalAngle and ContactFilter2D.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 ContactFilter2D.layerMask to be filtered.
IsFilteringNormalAngleChecks if the angle is within the normal angle range to be filtered.
IsFilteringTriggerChecks if the collider is a trigger and should be filtered by the ContactFilter2D.useTriggers to be filtered.
NoFilterSets the contact filter to not filter any ContactPoint2D.
SetDepthSets the ContactFilter2D.minDepth and ContactFilter2D.maxDepth filter properties and turns on depth filtering by setting ContactFilter2D.useDepth to true.
SetLayerMaskSets the ContactFilter2D.layerMask filter property using the layerMask parameter provided and also enables layer mask filtering by setting ContactFilter2D.useLayerMask to true.
SetNormalAngleSets the ContactFilter2D.minNormalAngle and ContactFilter2D.maxNormalAngle filter properties and turns on normal angle filtering by setting ContactFilter2D.useNormalAngle to true.