Over 11,000 five-star assets
Rated by 85,000+ customers
Supported by 100,000+ forum members
Every asset moderated by Unity
Unity Version | Built-in | URP | HDRP |
---|---|---|---|
2022.3.12f1 | Compatible | Compatible | Compatible |
Highly preformant detection algorythm encapsulated in the single class with 3 main capabilities:
1. calculate % of occupation in rectangular or circular area,
2. retrieve random free spot from rectangular or circular area,
3. check if defined rectangular or circular area is unoccupied or not.
Used algorythm is 5-20x faster than using any Physics.Cast approach and works either with internal shapes or existing colliders. Area is analyzed and random free spot retrieved usually within few miliseconds! Works only in 2D space.
Supported concepts:
- fixed boundaries to retrieve free spot
- padding for placed object not to overlap with occupied areas
- rectangular or circular detection area
- flexible resolution of the detection algorythm
- rectangles, circles, ellipses and points as occupied areas
- Collider2D (any) as occupied areas
- rotation and scaling of Collider2D
- DebugDraw functions to display results of analysis
Provided class is very easy to use and every public function, method and property is well documented. Free spot can be retrieve in 3 very easy steps:
1. create an instance with preffered settings (or use properties later)
var scanArea = new ScanArea2D(boundariesSize: new Vector2(40, 20));
2a. add occupied areas manually by providing shapes:
scanArea.AddPoint(new Vector2(4, 2));
scanArea.AddCircle(new Vector2(-2, 1), 2);
scanArea.AddRectangle(new Vector2(1, -3), new Vector2(3, 2));
2b. and/or enable detection of existing colliders for occupied spots
scanArea.ignoreAllColliders = false;
3. request new random available spot for object of defined size
Vector2 freeSpot = scanArea.GetRandomFreePositionForRectangle(objectSize, areaCenter, areaRadius);
Free Spot Finder 2D
