Sign in to follow this  
LuFe

Tiled Map colison

Recommended Posts

I make something like in this article http://www.gamedev.net/reference/articles/article1256.asp , to display the map. When i make this, how do i test collsion?

Share this post


Link to post
Share on other sites
For a simple 2d tiled environment, axis-aligned bounding boxes (rectangles in 2d) are a good choice. It's fairly easy to implement collision detection and response that seems natural. Another option would be to surround your character or whatever with a circle (easy) or a capsule (a bit harder, but might fit better), and make the tile obstacles AABBs. This can actually be even easier to code than the AABB version.

Also, just to be clear, collision detection doesn't really have anything to do with OpenGL per se, even though the article you refer to uses OpenGL.

Share this post


Link to post
Share on other sites
I post in OpenGL forum because the OGL cordinate system.
I have maked 2D tile based games with good colision, but in Allegro, where I test the position by x(0 to 640) and y(0 to 480).
In OGL, is diferent, -1 to 1, and iam confused with the collision

Share this post


Link to post
Share on other sites
Quote:
I post in OpenGL forum because the OGL cordinate system.
I have maked 2D tile based games with good colision, but in Allegro, where I test the position by x(0 to 640) and y(0 to 480).
In OGL, is diferent, -1 to 1, and iam confused with the collision
I didn't read all of the article you referred to, so I don't know how it sets up the coordinate range. But you can make it whatever you want. You can set things up so that that the screen runs from -1 to +1 horizontally, or -320 to +320, or 0 to 640, or whatever. You can accomplish this through perspecive projection, or (I recommend this) orthographic projection.

If +y goes down in Allegro, you'll have to adjust for that 'cause in OpenGL +y goes up by default. In any case, it sounds like you want an x range of 0 to 640 and a y range of 0 to 480. This can easily be done using an orthographic projection matrix, optionally in combination with the modelview matrix.

Share this post


Link to post
Share on other sites
Here is the easiest way to do 2D collisions, use a 2d array that matches the tilemap and mark the map with a symbol "?" whatever you want to denote this is not allowed to be passed through. Fast, and easy no need for AABB or anything like that. HTH

Share this post


Link to post
Share on other sites
Quote:
Here is the easiest way to do 2D collisions, use a 2d array that matches the tilemap and mark the map with a symbol "?" whatever you want to denote this is not allowed to be passed through. Fast, and easy no need for AABB or anything like that.
That will only really work if your character moves in tile-sized steps. Otherwise, you'll have to figure out which tiles the character rect is overlapping and respond accordingly, at which point you might as well use AABBs. Plus, AABBs aren't that hard to work with, especially in 2d.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this