Search Unity

How can I check if there exists something in a circle?

Discussion in 'Getting Started' started by lord_wayney, Jun 1, 2019.

  1. lord_wayney

    lord_wayney

    Joined:
    May 13, 2018
    Posts:
    6
    Hi all,

    Currently I am working on a 2D game about "Planting". I would do sowing by draging the seed out of inventory to the ground. In order to keep the plants not too dense, I need to check if the position of ground and a circle zone with the position as the center point have already sowed other seeds. I know how to check something in a circle, just make a vecto2.distance( sth.positon, center.position). But now I have the center.position and distance, how can I get to know if there is something inside the circle?
     
  2. Vryken

    Vryken

    Joined:
    Jan 23, 2018
    Posts:
    2,106
    lord_wayney likes this.
  3. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,438
    and if you dont have physics, colliders on those,
    then can manually check all plants, if they are within that range to your center position.

    if you have too many plants to check, could have them assigned into grid cells,
    and then allow only few objects to be placed within that cell. (they dont need to snap to grid, but just to keep track of which cell they are)
     
    lord_wayney likes this.