- Home /
Check when an object covers another entirely
Hello, 2D game. I have a large object in the center of the screen which doesn't move. There are many small objects that appear on the edge of the screen and move towards the large object. When they reach the large object, they continue their trajectory towards the center of the screen (no collider). The small objects just hide behind the big one. I would like to check for the moment when the small object disappears behind the large one entirely. Any help would be greatly appreciated!
For arbitrary shaped objects, this can be a difficult, and computationally expensive operation. There are a number of different approximations. For example for a convex 'large object', you can Raycast() towards negative 'z' from the four corners of the bounds of the smaller objects. If all the Raycasts hit the large object, it is occluded. A description of the properties of the large and small objects would be helpful. And/or a screen shot would be helpful.
This is a great idea. Thank you! I'm just working with stand-in rectangles and triangles right now, I'll be designing the elements's final sprites later when I have the logic worked out. This should be enough to get me started, though. Thanks again!
If the rectangles are axes aligned, then you can just check to see if the four points of the smaller rectangle are inside the larger rectangle. See Rect.Overlaps() for a first test, and then Rect.Contains().
Your answer
Follow this Question
Related Questions
Overlap in Google Chrome and Safari 2 Answers
overlap between scenes!!! 1 Answer
Wrong sprites overlapping 1 Answer
Object intersection 0 Answers
(2D intersection+picture)How to show up the invisible object when intersect with another object. 1 Answer