I've got a wall in my 2-D game. I've got everything except the not-allowing-you-into the wall part. I know I can use the intersect method on some Rectangles to know if they intersect, but I need to know where they intersect so that I can kick them out when they come into the rectangle.

I'm stumped, anyone got a way to do this?

the problem is here:
-----------
| |
| |
-----------
-------
| |
| |
| |
-------
(Those two boxes intersect, and they're as wide as the top parts. The formatting on this site won't allow me to add the extra spaces for some reason). The problem is:
I can detect if one x is greater than the other, and that tells me one side, but what if it's both above, and to the side? I can't think of a way to tell me this.

Thanks,
Jack

P.S. Now that I re-read that, its slightly confusing... please ask me if you don't understand. Thanks!

Recommended Answers

All 5 Replies

Put the diagram in code tags and see it that preserves the formatting

----------
|        |
|        |
----------

but what if it's both above, and to the side?

Can you explain what you mean.

I meant that I wanted:
(to use your suggestion)

--------|
|       |
|       | 
-- .....|
  |     |
  |     |
  -------

(The periods are rectangle overlap)
In this diagram, the two rectangles overlap at the corners, I haven't figured out how to solve this. I came up with 13 possible situations, all would require different types of logic. For instance, the corners, no corners, edges, bottoms without corners, middle, etc.

The other problem is that of dealing with the walls (really the corners, and middles), is where to put an Entity that is in the wall.

Thanks,
Jack

For the overlap you show, what info do you want about that overlap? A rectangle that encloses the overlap? In the case above, the rectangle would have a 0 height.

No, I wanted to tell if this overlap was happening, as opposed to another type, like on its edge. Also, I can't decide what to do when I detect an overlap of this type. Do I send it to another place (not on rectangle), or what?

Thanks,
Jack Townsend

What is the "type" of overlap shown? What are the types of overlaps?
The info about the overlap would be if it happened or not: true or false.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.