• FEATURED

View more

View more

View more

### Image of the Day Submit

IOTD | Top Screenshots

### The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

# Collisions with non-rectangular geometry

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

3 replies to this topic

### #1thok  Members

Posted 30 December 2011 - 05:59 AM

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!

### #2japro  Members

Posted 30 December 2011 - 06:32 AM

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.

### #3thok  Members

Posted 30 December 2011 - 06:55 AM

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!

### #4Narf the Mouse  Members

Posted 30 December 2011 - 11:02 AM

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.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.