How to check trigger overlap area? (with Image)

Helo, I’am wroking on a parking game. And I am stuck at what percentage of my car is overlapping to park area. Both use “Box Collider”.

If you can, just check whether four points (the four corners of your car) lie within the parking space’s bounding volume. This is a much easier approach.

If you need a little more data, check the car’s position and orientation against the parking spot’s center and orientation. This allows testing a parking job’s accuracy with a high degree of fidelity, and is computationally trivial. A distance of one quarter of a car width might be the worst possible “successful” park job, and the Dot Product of the car’s forward and the parking spot’s forward will give you a scalar value representing alignment. Definitely sounds like the way to go.


I mention the alternative below because it’s useful in other situations, and can give you an intersection mesh, accurate overlap percentages, and other relevant data…

If you can simplify a problem to 2D, do so. Definitely looks like you can. This means discarding the Y axis information on your two boundary objects and conducting the overlap check in 2D.

Numerous discussions on this topic exist; it becomes a “simple” math problem. You might be able to find a geometry library that does such calculations for you with relative ease. Otherwise, you’ll need to hunt down a helpful paper or article which discusses how to calculate the area of intersection between two rectangles. It should make for a long, boring, educational afternoon. :wink: