Archived

This topic is now archived and is closed to further replies.

Simple 2D collision help

This topic is 5644 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

In my game my menu selection boxes are all trapeziums (quadrilaterals, polygons....whatever) and I am having trouble with the collision of a point (the cursor) inside of them. Here is what my polygon/trapezium/quadrilateral looks like: ******* ********* *********** ************* *************** I know how to check for the rectangle part (well of course, that''s the easy bit!) but I am having troubles for the right side slope part. I was thinking of breaking the polygon up into a rectangle and a triangle, but then that leads to something else: triangle collision. Could anyone please help me with this? Or maybe point to some tutorials/articles on this?? (I''ve been checking around already, but failed to find something suitable) Thanks for your time (Remember all I want to check is a single point inside of the polygon)

Share on other sites
make a line from the cursor point, to somewhere outside the polygon. If that line intersects an even number of edges, the point is outside the polygon, if the line intersects an odd number of edges, the point is inside the polygon

My Site

Share on other sites
The rough and tough way to do it is with some nice geometry. We all remember having to draw things like:

y > x + 3;

With the dotted line, and the shaded area above. Well, lucky for us, we can make if statements with multiple parts

This means that whenever we''re working with concave shapes, as you are, you can simply do a multipart if statement to test if the point is in the shape.

So you''d have something like x > leftBorder && y > bottomBorder && y < topBorder && y < -x + constant (just a guess of the slope). That''s how I did collision in my shooter.

--Vic--

The future of 2D game development:
Flat Red Ball

1. 1
2. 2
3. 3
Rutin
22
4. 4
5. 5

• 10
• 16
• 14
• 9
• 9
• Forum Statistics

• Total Topics
632928
• Total Posts
3009271
• Who's Online (See full list)

There are no registered users currently online

×