Public Group

# Collisions with non-rectangular geometry

This topic is 2543 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.

1. 1
2. 2
Rutin
21
3. 3
4. 4
A4L
15
5. 5
khawk
14

• 13
• 26
• 10
• 11
• 9
• ### Forum Statistics

• Total Topics
633737
• Total Posts
3013612
×

## Important Information

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!