# Collision of polygons in 2D vector-based simulation

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

## Recommended Posts

Hi. I've just been thinking about collision handling in this vector-based game engine I'm trying to develop. All the objects are polygons with float-value vertices along with (x, y) coordinates for their "centres." I'm trying to see if I can develop "line-perfect" collision. What I do is before I actually move the objects in the game I use their velocities to calculate what the coordinates of their vertices will be. I create lines between these vertices for each object, as well as lines between the vertices and their correspondents in the original polygon (so, when you draw the lines, the objects look kind of 3D if they're moving fast enough). To test for collision, I check if any of these lines from two objects intersect at all. I made lines between the vertices of the "shadow" shape and the real shape in case a polygon is moving so fast it would be translated completely past another polygon when it's actually updated. Here's an image to help visualizing this: http://img197.echo.cx/img197/2035/collisiondiagram4tg.jpg What I want to do is if two objects will collide the update method would be altered for them so that they'd be just touching in the next frame, instead of overlapping. To keep the unit time on track I'd figure out what percentage of the unit time it would take the objects to move close enough to touch then figure out where they'd move in the remaining time based on whatever physics I use, which is what gets drawn to the screen.

##### Share on other sites
Not sure what you are asking exactly. Some collision response?

This below is an algorithm for swept collision detection (using velocities), which should be faster than ray-casting every points.

http://members.gamedev.net/oliii/PolyColly3.zip

And since you have the contact for the lines an the polygon, it's simply a matter of moving the objects to the time of contact, so they just touch, or take the earliest one. As for the response, anything goes. Rigid bodies, velocity reflection, ...

http://uk.geocities.com/olivier_rebellion/Polycolly.zip

that's an earlier version of the code. It's gor examples and docs for collision response, contact calculation, and so forth.

This one also has a code + doc about ray-polygon intersections.

##### Share on other sites
I downloaded your tutorials oliii. They seem good though it might take me a while to wrap my head around the math. Thank you anyway.

I guess my real question is how do I determine the time (starting from time = 0) at which two moving polygons, either convex or concave, contact each other before overlapping.

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 11
• 15
• 11
• 11
• 9
• ### Forum Statistics

• Total Topics
634151
• Total Posts
3015825
×