Free Spot Finder 2D

The Free Spot Finder 2D is a highly performant area analyzer that can detect remaining unoccupied spots in circular and rectangular 2D areas. It provides three main capabilities:

  1. Calculate the percentage of occupation in a rectangular or circular area.
  2. Retrieve a random free spot from a rectangular or circular area.
  3. Check if a defined rectangular or circular area is unoccupied or not.

The algorithm used is 5-20x faster than using any Physics.Cast approach and works with internal shapes or existing colliders. It analyzes the area and retrieves a random free spot usually within a few milliseconds.

The package supports various concepts, including:

  • Fixed boundaries to retrieve free spots
  • Padding for placed objects to avoid overlapping with occupied areas
  • Rectangular or circular detection areas
  • Flexible resolution of the detection algorithm
  • 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

The provided class is easy to use, and every public function, method, and property is well documented. To retrieve a free spot, you can follow these three easy steps:

  1. Create an instance with preferred settings (or use properties later)
  2. Add occupied areas manually by providing shapes or enable detection of existing colliders
  3. Request a new random available spot for an object of defined size

The class is encapsulated in a single class called ScanArea2D, which can be placed anywhere in your project folder structure. It has no specific dependencies on external libraries and requires only System and UnityEngine.

The ScanArea2D class is a single class that encapsulates all the logic. It can be created ad-hoc just before requesting a free spot or maintained for a longer duration for better performance in specific cases. The class has the following exposed methods and properties:

Exposed analytical methods:

  • GetOccupation
  • GetRandomFreePosition
  • GetRandomFreePositionForCircle
  • GetRandomFreePositionForRectangle
  • TryGetRandomFreePosition
  • TryGetRandomFreePositionForCircle
  • TryGetRandomFreePositionForRectangle
  • IsFree

Exposed shape methods:

  • AddPoint
  • UpdatePoint
  • AddCircle
  • UpdateCircle
  • AddRectangle
  • UpdateRectangle
  • RemoveShape

Exposed setting methods:

  • SetBoundaries
  • RemoveBoundaries

Exposed properties:

  • boundariesCenter
  • boundariesSize
  • baselineResolution
  • fixedResolution
  • ignoreAllColliders
  • ignoreAdvancedColliders

Free Spot Finder 2D - Asset Store

πŸ€– Chat with AI

AI is typing

Suggested Posts

SolarSoft Platformer Free: A Beginner-Friendly 2D Platformer Framework

SolarSoft Platformer Free: A Beginner-Friendly 2D Platformer Framework Thumbnail

Free Fall 2D Game Template

Free Fall 2D Game Template Thumbnail

Smart Lighting 2D: Advanced 2D Lighting Solution for Unity

Smart Lighting 2D: Advanced 2D Lighting Solution for Unity Thumbnail

Blark 2D Animated Character

Blark 2D Animated Character Thumbnail

2D Pixel Art Plains Biome

2D Pixel Art Plains Biome Thumbnail

Free Playing Cards Pack for Unity

Free Playing Cards Pack for Unity Thumbnail