🤔

Physics queries (2D): General#

Use the correct class#

You must be using functions from the Physics2D class. Physics calls will not interact with 2D physics.

If you are calling a query like collider2D.Raycast(... from a collider, then you are using a method that can only hit that single collider.
Make sure you understand this, or instead, use the static method Physics2D.Raycast that queries all the colliders in the scene.

Issues with colliders#

Correct use of ContactFilter2D#

A newly constructed ContactFilter2D will not be correctly configured. Check that you understand how to use the API using the example below.

Example usage#

var filter = new ContactFilter2D().NoFilter();

// Optional filtering:
filter.SetLayerMask(1 << 2); // Used to avoid having to set .useLayerMask too.
filter.SetDepth(-1, 1); // Used to avoid having to set .useDepth, comes with additional validation.
filter.SetNormalAngle(0, 180); // Used to avoid having to set .useNormalAngle, comes with additional validation.
filter.useTriggers = false; // Disables contact results based on trigger collider involvement.

// Example query
int resultCount = Physics2D.OverlapCircle(transform.position, radius, filter, results);

Notes on setup#


I am still having problems with my query.