Jump to content

  • Log In with Google      Sign In   
  • Create Account


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.

  • You cannot reply to this topic
3 replies to this topic

#1 thok   Members   -  Reputation: 669

Like
0Likes
Like

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!

Sponsor:

#2 japro   Members   -  Reputation: 887

Like
1Likes
Like

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.

#3 thok   Members   -  Reputation: 669

Like
0Likes
Like

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!

#4 Narf the Mouse   Members   -  Reputation: 318

Like
0Likes
Like

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.



PARTNERS