- Home /
How to calculate the amount of overlap between two 2D objects.
I am trying to measure the amount of overlap between two 2d objects, for example two circles or two rectangles. The game involves lining up two rectangles and I need a way to measure how much one shape overlaps the other.
You will probably want to use something like https://docs.unity3d.com/ScriptReference/Collider-bounds.html and https://docs.unity3d.com/ScriptReference/Collider.ClosestPoint.html in your OnCollisionStay2D. $$anonymous$$aybe if the centerpoint of your shape bounds is a certain distance from the center point of your overlapping shape would you "do something".
Yeah, what I ended up doing is just calculating the distance vector between the two objects and use that to tell how far the objects are from each other, it will "basically" do the same thing of showing how much they overlap, if they are overlapping a lot then the distance will be a small value is what I mean.
Your answer