• Create Account

Banner advertising on our site currently available from just \$5!

2d tile map collision

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.

#1nick5454  Members   -  Reputation: 137

Like
0Likes
Like

Posted 20 June 2010 - 08:53 AM

What is the best way for collision detection? ( 2d collision in opengl es for iphone with Objective C)

I can do a ray intersection on every tile map which my map is pretty big and may contain several hundred tiles.

Although I guess I could do a for loop for only visible tiles and calculate whether the players shape intersects any visible tile.

Is that the best way to do it or is there better prescribed ways to determine if a player runs over a tile that has illegal movement?

just curious.
Nick

#2Captain P  Members   -  Reputation: 1092

Like
0Likes
Like

Posted 20 June 2010 - 09:34 AM

What kinds of collision checks do you need? You've got a 2D grid, but what kind of shapes are you working with? Do you only need to check for collisions between a player and the world, or also against other game objects? Do you need to determine if one game object can 'see' another game object?

Either way, if you've got a rectangular shape for your player, and tiles are either completely solid or completely open, then it's fairly easy to check if the player collides with solid tiles. Based on it's position and dimension, and the tile size, you can calculate which rows and collumns it (partially) overlaps. Then check if any of those tiles are solid.

You'll probably want to know a bit more than that, though, such as how far the player intersects with any of those tiles. You could then 'push out' the player accordingly, or partially revert his movement.