Public Group

# Collisions with non-rectangular geometry

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

## Recommended Posts

Hi there,

I'm currently working on my first game from scratch for the learning experience and for fun. It's a simple 2D platformer written in Java using basic Swing and AWT components for the graphics. Nothing fancy.

For the sake of simplicity, all of the entities in my game (which, at the moment, only consists of the player character and terrain/platforms) are represented by rectangles. This makes collision detection and response (I'm using a simple projection method) incredibly simple: All entities are rectangles and thus all collision intersections are rectangles. Collision intersections are created using Rectangle2D.createIntersection() (http://docs.oracle.com/javase/6/docs/api/java/awt/geom/Rectangle2D.html#createIntersection(java.awt.geom.Rectangle2D).

For this project, I don't plan on using anything more sophisticated than this.

However, for future projects I'm curious to know about how collisions are handled with other types of geometry, such as triangles. I imagine this is problem that you would need to solve in order to have sloped terrain, right? I've done a bit of searching on the web and so far haven't come up with much. Can anyone suggest any articles or other resources that deal with these kind of collisions?

Cheers!

##### Share on other sites
For arbitrary polygon collision look up SAT (Separating Axis Theorem) algorithms. Not sure if there are specific "named" algorithms for the case of slopy terrain. What I'd do there is just use the "center of the base" of the character and raycast that to the terrain and than use the slope appropriately.

##### Share on other sites

For arbitrary polygon collision look up SAT (Separating Axis Theorem) algorithms. Not sure if there are specific "named" algorithms for the case of slopy terrain. What I'd do there is just use the "center of the base" of the character and raycast that to the terrain and than use the slope appropriately.

Nice! This was one of the first search results for Separating Axis Theorem: http://www.metanetsoftware.com/technique/tutorialA.html This seems to be just what I'm looking for.

Thanks!

##### Share on other sites
One thing you will find on the internet is things like "There is no mathematical method to test for concave object collision". What searching didn't tell me, at least, is that you can simply test all the faces of an object versus all the other faces, for collision (this won't tell you if one object is entirely in the other, but provided you've got swept collision, that's not going to happen without faces colliding first, anyway).

This can be sped up through various methods, such as only testing faces that are within both objects' bounding spheres/boxes and remembering which faces collided last.

• ### Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• 16
• 15
• 9
• 11
• 15