Search Unity

Question Physics2d.OverlapCircle

Discussion in 'Physics' started by The-Magician, May 20, 2023.

  1. The-Magician

    The-Magician

    Joined:
    Dec 10, 2022
    Posts:
    4
  2. Andrewsr3

    Andrewsr3

    Joined:
    Aug 1, 2023
    Posts:
    1
    Last edited: Aug 2, 2023
  3. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,500
    No, it doesn't return the nearest object to the center, it does what it describes; returns all colliders overlapping the specified shape (circle in this case).

    You can quickly iterate the returned colliders to determine that should you wish whether it be by the Rigidbody2D.position, Transform.position etc.

    The order of overlapped results is always undefined in terms of XY but as the docs mention, the order will be sorted by Transform.z (which isn't a physics property but a Transform property).

    Any "cast" query (line-cast, ray-cast, circle-cast, capsule-cast etc) is ordered by hit distance. (2D Only, 3D physics does no sorting).